/** * CSV Parser Stream * * True streaming CSV parser using cross-platform stream module. * Works identically in both Node.js and Browser environments. */ import { Transform } from "../../stream/index.js"; import type { CsvParseOptions, RowTransformFunction, RowValidateFunction, Row } from "../types.js"; /** * Transform stream that parses CSV data row by row * * @example * ```ts * const parser = new CsvParserStream({ headers: true }); * readable.pipe(parser).on('data', (row) => console.log(row)); * ``` */ export declare class CsvParserStream extends Transform { private options; private parseConfig; private parseState; /** * Shared sink array for processCompletedRowCore's errors parameter. * The streaming parser emits errors via 'data-invalid' events instead, * so this array is cleared after each call to prevent unbounded growth. */ private readonly parseErrorsSink; private buffer; private decoder; private scanner; private _rowTransform; private _rowValidator; private autoDetectDelimiter; private delimiterDetected; private chunkBuffer; private chunkSize; private totalRowsProcessed; private isFirstChunk; private chunkAborted; private beforeFirstChunkApplied; private bomStripped; private toLineReached; private headersEmitted; private totalCharsProcessed; private backpressure; private pendingCallback; push: (chunk: Row | string | null) => boolean; write: { (chunk: Uint8Array, callback?: (error?: Error | null) => void): boolean; (chunk: Uint8Array, encoding?: string, callback?: (error?: Error | null) => void): boolean; (chunk: string, callback?: (error?: Error | null) => void): boolean; (chunk: string, encoding?: string, callback?: (error?: Error | null) => void): boolean; }; constructor(options?: CsvParseOptions); /** * Called when downstream is ready for more data (backpressure released). * Resume processing if we were paused due to backpressure. */ _read(_size: number): void; /** * Set a transform function to modify rows before emitting * Supports both sync and async transforms */ transform(transformFunction: RowTransformFunction): this; /** * Set a validate function to filter rows * Invalid rows emit 'data-invalid' event */ validate(validateFunction: RowValidateFunction): this; _transform(chunk: Uint8Array | string, _encoding: string, callback: (error?: Error | null, data?: Row) => void): void; _flush(callback: (error?: Error | null) => void): void; /** * Clean up resources when stream is destroyed. * Handles pending backpressure callbacks and clears buffers. */ _destroy(error: Error | null, callback: (error: Error | null) => void): void; private flushCurrentRow; private flushFastModeRemainder; /** * Push buffered rows to stream with backpressure support * @returns false if backpressure is applied (downstream is full) */ private pushBufferedRows; /** * Push a single row to stream with backpressure support * @returns false if backpressure is applied (downstream is full) */ private pushRow; /** * Invoke chunk callback and handle result (sync or async) */ private invokeChunkCallback; /** * Flush any remaining rows in the chunk buffer at the end of the stream */ private flushFinalChunk; /** * Reset info state for next row (used when skipping rows or after processing) */ private processBuffer; private getFastModeCompleteDataEnd; /** * Fast mode buffer processing - skips quote detection, splits directly by delimiter */ private processBufferFastMode; private buildRow; /** * Shared per-row handling for all four processing paths (processBuffer, processBufferFastMode, * flushCurrentRow, flushFastModeRemainder). * * Performs: lineNumber increment, toLine/skipLines checks, info tracking, maxRowBytes, * raw row assignment, shouldSkipRow, and processCompletedRow delegation. * * @returns "continue" — row processed, keep going * "skip" — row skipped, keep going * "stop" — toLine/maxRows reached; pendingRows already flushed via callback * "error" — error passed to callback */ private _handleParsedRow; /** * Process a completed row (shared logic for standard and fast mode) * Returns true if processing should continue, false if maxRows/toLine reached */ private processCompletedRow; private emitHeaders; /** * Check if a line should be skipped (comment or empty) */ private shouldSkipRow; private processPendingRows; /** * Flush the current chunk buffer to the chunk callback */ private flushChunk; private transformAndValidateRow; private validateRow; } /** * Create parser stream factory */ export declare function createCsvParserStream(options?: CsvParseOptions): CsvParserStream;