This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), |