UNPKG

@pujansrt/data-genie

Version:

High performant ETL engine written in TypeScript

36 lines (35 loc) 1.56 kB
import { DataWriter, DataRecord } from '../core/interfaces'; /** * NDJsonWriter class for writing data records to a file in NDJSON (Newline Delimited JSON) format. * Each DataRecord is stringified into a JSON object and written on a new line. * This is efficient for large datasets as it writes records incrementally without * holding all of them in memory. */ export declare class NDJsonWriter implements DataWriter { private filePath; private outputStream; /** * Constructs a new NDJsonWriter. * @param filePath The path to the output file. */ constructor(filePath: string); /** * Writes a single data record to the NDJSON file. * The record is stringified into a JSON object and appended with a newline. * @param record The DataRecord object to write. * @returns A Promise that resolves when the record has been written to the stream. */ write(record: DataRecord): Promise<void>; /** * Writes all data records from an asynchronous iterable to the NDJSON file. * @param records An AsyncIterableIterator of DataRecord objects. * @returns A Promise that resolves when all records have been written. */ writeAll(records: AsyncIterableIterator<DataRecord>): Promise<void>; /** * Closes the underlying write stream. This should be called when all data has been written * to ensure all buffered data is flushed to the file and resources are released. * @returns A Promise that resolves when the stream is closed. */ close(): Promise<void>; }