Skip to content

Instantly share code, notes, and snippets.

@sp71
sp71 / FileChunker.go
Created January 30, 2025 02:33
FileChunker efficiently writes large datasets to multiple files in chunks, supporting plain text and gzip formats.
/*
FileChunker efficiently writes large datasets to multiple files in chunks, supporting plain text and gzip formats.
The FileChunker validates each line of input data, writes it to the current file, and manages file rotation based on
specified size limits. It operates asynchronously, processing input data from a buffered channel and ensuring that
data is flushed to disk in a non-blocking manner. This is particularly useful for handling large datasets that need
to be split into manageable file sizes for storage or further processing.
*/
package ciem
@sp71
sp71 / FileManager.swift
Created March 11, 2021 11:43
Format JSON into Label
import UIKit
class FileManager {
static func decodeJSON<T: Decodable>(fileName: String?, subdirectory: String?) -> T? {
guard let filename = fileName else { return nil }
if filename.isEmpty { return nil }
let decoder = JSONDecoder()
guard
let url = Bundle.main.url(forResource: filename, withExtension: "json", subdirectory: subdirectory),
let data = try? Data(contentsOf: url),