UNPKG

@push.rocks/smartstream

Version:

A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.

35 lines (34 loc) 1.4 kB
export interface IStreamToolsRead<TInput, TOutput> { done: () => void; write: (writeArg: TInput) => Promise<void>; } /** * The read function is called when data needs to be read into the stream. */ export interface IStreamReadFunction<TInput, TOutput> { (toolsArg: IStreamToolsRead<TInput, TOutput>): Promise<void>; } export interface IStreamToolsWrite<TInput, TOutput> { truncate: () => void; push: (pushArg: TOutput) => void; } /** * The write function is called whenever a chunk is written to the stream. */ export interface IStreamWriteFunction<TInput, TOutput> { (chunkArg: TInput, toolsArg: IStreamToolsWrite<TInput, TOutput>): Promise<any>; } export interface IStreamFinalFunction<TInput, TOutput> { (toolsArg: IStreamToolsWrite<TInput, TOutput>): Promise<TOutput | void>; } export interface WebDuplexStreamOptions<TInput, TOutput> { readFunction?: IStreamReadFunction<TInput, TOutput>; writeFunction?: IStreamWriteFunction<TInput, TOutput>; finalFunction?: IStreamFinalFunction<TInput, TOutput>; } export declare class WebDuplexStream<TInput = any, TOutput = any> extends TransformStream<TInput, TOutput> { options: WebDuplexStreamOptions<TInput, TOutput>; constructor(optionsArg: WebDuplexStreamOptions<TInput, TOutput>); private _startReading; static fromUInt8Array(uint8Array: Uint8Array): WebDuplexStream<Uint8Array, Uint8Array>; }