///
import { z } from "zod";
import { EventEmitter } from "events";
import { Options } from "./parse";
export interface CSVStreamError {
index: number;
row: Record;
error: z.ZodError;
}
interface CSVStreamEvents {
data: (data: z.infer) => void;
error: (error: CSVStreamError) => void;
end: () => void;
headers: (headers: string[]) => void;
}
declare interface CSVStream {
on>(event: E, listener: CSVStreamEvents[E]): this;
emit>(event: E, ...args: Parameters[E]>): boolean;
}
/**
* A class that processes CSV data as a stream and emits events for parsed records
*/
declare class CSVStream extends EventEmitter {
private schema;
private options?;
private headers;
private buffer;
private rowIndex;
private headersParsed;
constructor(schema: T, options?: Options);
/**
* Write a chunk of CSV data to the stream
* @param chunk - A chunk of CSV data
*/
write(chunk: string): void;
/**
* End the stream and process any remaining data
*/
end(): void;
private processBuffer;
/**
* Find the position of a newline character that is not inside quoted content
* This handles both regular quotes and escaped quotes
*/
private findSafeNewlinePosition;
private processRow;
}
/**
* Process CSV data in chunks and emit events for parsed records
* @param schema - Zod schema to validate each record against
* @param options - CSV parsing options
* @returns A function that accepts chunks of CSV data
*
* @example
* ```ts
* const processor = processCSVInChunks(schema);
*
* processor.on('data', (data) => {
* console.log('Valid row:', data);
* });
*
* processor.on('error', ({ index, error }) => {
* console.log(`Invalid row at index ${index}:`, error);
* });
*
* // Process chunks of data
* processor.write('name,age\n');
* processor.write('John,30\n');
* processor.write('Jane,invalid\n');
* processor.end();
* ```
*/
export declare function processCSVInChunks(schema: T, options?: Options): CSVStream;
export {};