import { CSVRecord, StringCSVParserStreamOptions } from '../../core/types'; /** * A transform stream that converts a stream of strings into a stream of CSV records. * Wraps a StringCSVParser instance to provide streaming CSV parsing. * * @template Header - The type of the header row * @template Format - Output format: 'object' or 'array' * * @category Low-level API * * @param parser - StringCSVParser instance to use for parsing (required). Use {@link createStringCSVParser} to create one. * @param options - Stream-specific options (backpressureCheckInterval, etc.) * @param writableStrategy - Strategy for the writable side (default: `{ highWaterMark: 65536, size: chunk => chunk.length }`) * @param readableStrategy - Strategy for the readable side (default: `{ highWaterMark: 256 }`) * * @remarks * **Recommended: Use the factory function** * * For simpler usage, use {@link createStringCSVParserStream} which handles parser creation internally: * ```ts * import { createStringCSVParserStream } from 'web-csv-toolbox'; * * await fetch('data.csv') * .then(res => res.body) * .pipeThrough(new TextDecoderStream()) * .pipeThrough(createStringCSVParserStream({ header: ['name', 'age'] })) * .pipeTo(yourProcessor); * ``` * * **Direct instantiation (advanced)** * * If you need direct access to the parser or want to reuse it, use the constructor directly: * ```ts * import { createStringCSVParser, StringCSVParserStream } from 'web-csv-toolbox'; * const parser = createStringCSVParser({ header: ['name', 'age'] }); * stringStream.pipeThrough(new StringCSVParserStream(parser)); * ``` * * **Queuing Strategy:** * - Writable side: Counts by string length (characters). Default highWaterMark is 65536 characters (≈64KB). * - Readable side: Counts each record as 1. Default highWaterMark is 256 records. * * **Backpressure Handling:** * The transformer monitors `controller.desiredSize` and yields to the event loop when backpressure * is detected (desiredSize ≤ 0). This prevents blocking the main thread during heavy processing * and allows the downstream consumer to catch up. * * @example Recommended: Using factory function * ```ts * import { createStringCSVParserStream } from 'web-csv-toolbox'; * * await fetch('data.csv') * .then(res => res.body) * .pipeThrough(new TextDecoderStream()) * .pipeThrough(createStringCSVParserStream()) * .pipeTo(new WritableStream({ * write(record) { * console.log(record); // { name: 'Alice', age: '30' } * } * })); * ``` * * @example Direct instantiation with parser * ```ts * import { createStringCSVParser, StringCSVParserStream } from 'web-csv-toolbox'; * * const parser = createStringCSVParser({ header: ['name', 'age'] }); * const stream = new StringCSVParserStream(parser); * * stringStream.pipeThrough(stream); * ``` * * @example With custom queuing strategies * ```ts * import { createStringCSVParser, StringCSVParserStream } from 'web-csv-toolbox'; * * const parser = createStringCSVParser({ header: ['name', 'age'] }); * const stream = new StringCSVParserStream( * parser, * { backpressureCheckInterval: 50 }, * { highWaterMark: 131072, size: (chunk) => chunk.length }, * new CountQueuingStrategy({ highWaterMark: 512 }) * ); * * await fetch('large-file.csv') * .then(res => res.body) * .pipeThrough(new TextDecoderStream()) * .pipeThrough(stream) * .pipeTo(yourProcessor); * ``` */ export declare class StringCSVParserStream
= readonly string[], Format extends "object" | "array" = "object"> extends TransformStream> { readonly parser: { parse(chunk?: string, options?: { stream?: boolean; }): IterableIterator>; }; /** * Yields to the event loop to allow backpressure handling. * Can be overridden for testing purposes. * @internal */ protected yieldToEventLoop(): Promise; constructor(parser: { parse(chunk?: string, options?: { stream?: boolean; }): IterableIterator>; }, options?: StringCSVParserStreamOptions, writableStrategy?: QueuingStrategy, readableStrategy?: QueuingStrategy>); }