import { Duplex, type Writable } from 'node:stream'; export interface BufferStreamOptions { objectMode: boolean; } export type BufferStreamItem, T> = O extends { objectMode: true; } ? T : Buffer; export type BufferStreamPayload, T> = O extends { objectMode: true; } ? T[] : Buffer; export type BufferStreamHandler, T> = (payload: BufferStreamPayload) => Promise>; export type BufferStreamCallback, T> = (err: Error | null, payload: BufferStreamPayload, cb: (err: Error | null, payload?: null | BufferStreamPayload) => void) => void; /** * Buffer the stream content and bring it into the provided callback */ declare class BufferStream> extends Duplex { private _options; private _bufferCallback; private _finished; private _buffer; /** * @param bufferCallback {Function} A function to handle the buffered content. * @param options {Object} inherits of Stream.Duplex, the options are passed to the parent constructor so you can use it's options too. * @param options.objectMode {boolean} Use if piped in streams are in object mode. In this case, an array of the buffered will be transmitted to the callback function. */ constructor(bufferCallback: BufferStreamCallback | BufferStreamHandler, options?: O); _write(chunk: BufferStreamItem, encoding: Parameters[1], done: () => void): void; _read(): void; _bufferStreamCallbackWrapper(err: Error): void; _bufferStreamError(err: Error): void; } /** * Utility function if you prefer a functional way of using this lib * @param bufferCallback * @param options * @returns Stream */ export declare function bufferStream>(bufferCallback: BufferStreamCallback, options?: O): BufferStream; /** * Utility function to buffer objet mode streams * @param bufferCallback * @param options * @returns Stream */ export declare function bufferObjects(bufferCallback: BufferStreamCallback<{ objectMode: true; }, T>, options: Omit): BufferStream; export { BufferStream };