declare module 'stream' { import { EventEmitter, Abortable } from 'events'; import * as streamPromises from "stream/promises"; class internal extends EventEmitter { pipe(destination: T, options?: { end?: boolean; }): T; } namespace internal { class Stream extends internal { constructor(opts?: ReadableOptions); } interface StreamOptions extends Abortable { emitClose?: boolean; highWaterMark?: number; objectMode?: boolean; construct?(this: T, callback: (error?: Error | null) => void): void; destroy?(this: T, error: Error | null, callback: (error: Error | null) => void): void; autoDestroy?: boolean; } interface ReadableOptions extends StreamOptions { encoding?: BufferEncoding; read?(this: Readable, size: number): void; } class Readable extends Stream implements NodeJS.ReadableStream { /** * A utility method for creating Readable Streams out of iterators. */ static from(iterable: Iterable | AsyncIterable, options?: ReadableOptions): Readable; readable: boolean; readonly readableEncoding: BufferEncoding | null; readonly readableEnded: boolean; readonly readableFlowing: boolean | null; readonly readableHighWaterMark: number; readonly readableLength: number; readonly readableObjectMode: boolean; destroyed: boolean; constructor(opts?: ReadableOptions); _construct?(callback: (error?: Error | null) => void): void; _read(size: number): void; read(size?: number): any; setEncoding(encoding: BufferEncoding): this; pause(): this; resume(): this; isPaused(): boolean; unpipe(destination?: NodeJS.WritableStream): this; unshift(chunk: any, encoding?: BufferEncoding): void; wrap(oldStream: NodeJS.ReadableStream): this; push(chunk: any, encoding?: BufferEncoding): boolean; _destroy(error: Error | null, callback: (error?: Error | null) => void): void; destroy(error?: Error): void; /** * Event emitter * The defined events on documents including: * 1. close * 2. data * 3. end * 4. error * 5. pause * 6. readable * 7. resume */ addListener(event: "close", listener: () => void): this; addListener(event: "data", listener: (chunk: any) => void): this; addListener(event: "end", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; addListener(event: "pause", listener: () => void): this; addListener(event: "readable", listener: () => void): this; addListener(event: "resume", listener: () => void): this; addListener(event: string | symbol, listener: (...args: any[]) => void): this; emit(event: "close"): boolean; emit(event: "data", chunk: any): boolean; emit(event: "end"): boolean; emit(event: "error", err: Error): boolean; emit(event: "pause"): boolean; emit(event: "readable"): boolean; emit(event: "resume"): boolean; emit(event: string | symbol, ...args: any[]): boolean; on(event: "close", listener: () => void): this; on(event: "data", listener: (chunk: any) => void): this; on(event: "end", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; on(event: "pause", listener: () => void): this; on(event: "readable", listener: () => void): this; on(event: "resume", listener: () => void): this; on(event: string | symbol, listener: (...args: any[]) => void): this; once(event: "close", listener: () => void): this; once(event: "data", listener: (chunk: any) => void): this; once(event: "end", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; once(event: "pause", listener: () => void): this; once(event: "readable", listener: () => void): this; once(event: "resume", listener: () => void): this; once(event: string | symbol, listener: (...args: any[]) => void): this; prependListener(event: "close", listener: () => void): this; prependListener(event: "data", listener: (chunk: any) => void): this; prependListener(event: "end", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; prependListener(event: "pause", listener: () => void): this; prependListener(event: "readable", listener: () => void): this; prependListener(event: "resume", listener: () => void): this; prependListener(event: string | symbol, listener: (...args: any[]) => void): this; prependOnceListener(event: "close", listener: () => void): this; prependOnceListener(event: "data", listener: (chunk: any) => void): this; prependOnceListener(event: "end", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; prependOnceListener(event: "pause", listener: () => void): this; prependOnceListener(event: "readable", listener: () => void): this; prependOnceListener(event: "resume", listener: () => void): this; prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; removeListener(event: "close", listener: () => void): this; removeListener(event: "data", listener: (chunk: any) => void): this; removeListener(event: "end", listener: () => void): this; removeListener(event: "error", listener: (err: Error) => void): this; removeListener(event: "pause", listener: () => void): this; removeListener(event: "readable", listener: () => void): this; removeListener(event: "resume", listener: () => void): this; removeListener(event: string | symbol, listener: (...args: any[]) => void): this; [Symbol.asyncIterator](): AsyncIterableIterator; } interface WritableOptions extends StreamOptions { decodeStrings?: boolean; defaultEncoding?: BufferEncoding; write?(this: Writable, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void; writev?(this: Writable, chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void; final?(this: Writable, callback: (error?: Error | null) => void): void; } class Writable extends Stream implements NodeJS.WritableStream { readonly writable: boolean; readonly writableEnded: boolean; readonly writableFinished: boolean; readonly writableHighWaterMark: number; readonly writableLength: number; readonly writableObjectMode: boolean; readonly writableCorked: number; destroyed: boolean; constructor(opts?: WritableOptions); _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void; _writev?(chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void; _construct?(callback: (error?: Error | null) => void): void; _destroy(error: Error | null, callback: (error?: Error | null) => void): void; _final(callback: (error?: Error | null) => void): void; write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean; write(chunk: any, encoding: BufferEncoding, cb?: (error: Error | null | undefined) => void): boolean; setDefaultEncoding(encoding: BufferEncoding): this; end(cb?: () => void): void; end(chunk: any, cb?: () => void): void; end(chunk: any, encoding: BufferEncoding, cb?: () => void): void; cork(): void; uncork(): void; destroy(error?: Error): void; /** * Event emitter * The defined events on documents including: * 1. close * 2. drain * 3. error * 4. finish * 5. pipe * 6. unpipe */ addListener(event: "close", listener: () => void): this; addListener(event: "drain", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; addListener(event: "finish", listener: () => void): this; addListener(event: "pipe", listener: (src: Readable) => void): this; addListener(event: "unpipe", listener: (src: Readable) => void): this; addListener(event: string | symbol, listener: (...args: any[]) => void): this; emit(event: "close"): boolean; emit(event: "drain"): boolean; emit(event: "error", err: Error): boolean; emit(event: "finish"): boolean; emit(event: "pipe", src: Readable): boolean; emit(event: "unpipe", src: Readable): boolean; emit(event: string | symbol, ...args: any[]): boolean; on(event: "close", listener: () => void): this; on(event: "drain", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; on(event: "finish", listener: () => void): this; on(event: "pipe", listener: (src: Readable) => void): this; on(event: "unpipe", listener: (src: Readable) => void): this; on(event: string | symbol, listener: (...args: any[]) => void): this; once(event: "close", listener: () => void): this; once(event: "drain", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; once(event: "finish", listener: () => void): this; once(event: "pipe", listener: (src: Readable) => void): this; once(event: "unpipe", listener: (src: Readable) => void): this; once(event: string | symbol, listener: (...args: any[]) => void): this; prependListener(event: "close", listener: () => void): this; prependListener(event: "drain", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; prependListener(event: "finish", listener: () => void): this; prependListener(event: "pipe", listener: (src: Readable) => void): this; prependListener(event: "unpipe", listener: (src: Readable) => void): this; prependListener(event: string | symbol, listener: (...args: any[]) => void): this; prependOnceListener(event: "close", listener: () => void): this; prependOnceListener(event: "drain", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; prependOnceListener(event: "finish", listener: () => void): this; prependOnceListener(event: "pipe", listener: (src: Readable) => void): this; prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this; prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; removeListener(event: "close", listener: () => void): this; removeListener(event: "drain", listener: () => void): this; removeListener(event: "error", listener: (err: Error) => void): this; removeListener(event: "finish", listener: () => void): this; removeListener(event: "pipe", listener: (src: Readable) => void): this; removeListener(event: "unpipe", listener: (src: Readable) => void): this; removeListener(event: string | symbol, listener: (...args: any[]) => void): this; } interface DuplexOptions extends ReadableOptions, WritableOptions { allowHalfOpen?: boolean; readableObjectMode?: boolean; writableObjectMode?: boolean; readableHighWaterMark?: number; writableHighWaterMark?: number; writableCorked?: number; construct?(this: Duplex, callback: (error?: Error | null) => void): void; read?(this: Duplex, size: number): void; write?(this: Duplex, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void; writev?(this: Duplex, chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void; final?(this: Duplex, callback: (error?: Error | null) => void): void; destroy?(this: Duplex, error: Error | null, callback: (error: Error | null) => void): void; } // Note: Duplex extends both Readable and Writable. class Duplex extends Readable implements Writable { readonly writable: boolean; readonly writableEnded: boolean; readonly writableFinished: boolean; readonly writableHighWaterMark: number; readonly writableLength: number; readonly writableObjectMode: boolean; readonly writableCorked: number; constructor(opts?: DuplexOptions); _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void; _writev?(chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void; _destroy(error: Error | null, callback: (error: Error | null) => void): void; _final(callback: (error?: Error | null) => void): void; write(chunk: any, encoding?: BufferEncoding, cb?: (error: Error | null | undefined) => void): boolean; write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean; setDefaultEncoding(encoding: BufferEncoding): this; end(cb?: () => void): void; end(chunk: any, cb?: () => void): void; end(chunk: any, encoding?: BufferEncoding, cb?: () => void): void; cork(): void; uncork(): void; } type TransformCallback = (error?: Error | null, data?: any) => void; interface TransformOptions extends DuplexOptions { construct?(this: Transform, callback: (error?: Error | null) => void): void; read?(this: Transform, size: number): void; write?(this: Transform, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void; writev?(this: Transform, chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void; final?(this: Transform, callback: (error?: Error | null) => void): void; destroy?(this: Transform, error: Error | null, callback: (error: Error | null) => void): void; transform?(this: Transform, chunk: any, encoding: BufferEncoding, callback: TransformCallback): void; flush?(this: Transform, callback: TransformCallback): void; } class Transform extends Duplex { constructor(opts?: TransformOptions); _transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void; _flush(callback: TransformCallback): void; } class PassThrough extends Transform { } /** * Attaches an AbortSignal to a readable or writeable stream. This lets code * control stream destruction using an `AbortController`. * * Calling `abort` on the `AbortController` corresponding to the passed * `AbortSignal` will behave the same way as calling `.destroy(new AbortError())` * on the stream. */ function addAbortSignal(signal: AbortSignal, stream: T): T; interface FinishedOptions extends Abortable { error?: boolean; readable?: boolean; writable?: boolean; } function finished(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, options: FinishedOptions, callback: (err?: NodeJS.ErrnoException | null) => void): () => void; function finished(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, callback: (err?: NodeJS.ErrnoException | null) => void): () => void; namespace finished { function __promisify__(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, options?: FinishedOptions): Promise; } type PipelineSourceFunction = () => Iterable | AsyncIterable; type PipelineSource = Iterable | AsyncIterable | NodeJS.ReadableStream | PipelineSourceFunction; type PipelineTransform, U> = NodeJS.ReadWriteStream | ((source: S extends (...args: any[]) => Iterable | AsyncIterable ? AsyncIterable : S) => AsyncIterable); type PipelineTransformSource = PipelineSource | PipelineTransform; type PipelineDestinationIterableFunction = (source: AsyncIterable) => AsyncIterable; type PipelineDestinationPromiseFunction = (source: AsyncIterable) => Promise

; type PipelineDestination, P> = S extends PipelineTransformSource ? (NodeJS.WritableStream | PipelineDestinationIterableFunction | PipelineDestinationPromiseFunction) : never; type PipelineCallback> = S extends PipelineDestinationPromiseFunction ? (err: NodeJS.ErrnoException | null, value: P) => void : (err: NodeJS.ErrnoException | null) => void; type PipelinePromise> = S extends PipelineDestinationPromiseFunction ? Promise

: Promise; interface PipelineOptions { signal: AbortSignal; } function pipeline, B extends PipelineDestination>( source: A, destination: B, callback?: PipelineCallback ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream; function pipeline, T1 extends PipelineTransform, B extends PipelineDestination>( source: A, transform1: T1, destination: B, callback?: PipelineCallback ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream; function pipeline, T1 extends PipelineTransform, T2 extends PipelineTransform, B extends PipelineDestination>( source: A, transform1: T1, transform2: T2, destination: B, callback?: PipelineCallback ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream; function pipeline, T1 extends PipelineTransform, T2 extends PipelineTransform, T3 extends PipelineTransform, B extends PipelineDestination>( source: A, transform1: T1, transform2: T2, transform3: T3, destination: B, callback?: PipelineCallback ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream; function pipeline, T1 extends PipelineTransform, T2 extends PipelineTransform, T3 extends PipelineTransform, T4 extends PipelineTransform, B extends PipelineDestination>( source: A, transform1: T1, transform2: T2, transform3: T3, transform4: T4, destination: B, callback?: PipelineCallback ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream; function pipeline( streams: ReadonlyArray, callback?: (err: NodeJS.ErrnoException | null) => void, ): NodeJS.WritableStream; function pipeline( stream1: NodeJS.ReadableStream, stream2: NodeJS.ReadWriteStream | NodeJS.WritableStream, ...streams: Array void)>, ): NodeJS.WritableStream; namespace pipeline { function __promisify__, B extends PipelineDestination>( source: A, destination: B, options?: PipelineOptions ): PipelinePromise; function __promisify__, T1 extends PipelineTransform, B extends PipelineDestination>( source: A, transform1: T1, destination: B, options?: PipelineOptions, ): PipelinePromise; function __promisify__, T1 extends PipelineTransform, T2 extends PipelineTransform, B extends PipelineDestination>( source: A, transform1: T1, transform2: T2, destination: B, options?: PipelineOptions ): PipelinePromise; function __promisify__, T1 extends PipelineTransform, T2 extends PipelineTransform, T3 extends PipelineTransform, B extends PipelineDestination>( source: A, transform1: T1, transform2: T2, transform3: T3, destination: B, options?: PipelineOptions ): PipelinePromise; function __promisify__, T1 extends PipelineTransform, T2 extends PipelineTransform, T3 extends PipelineTransform, T4 extends PipelineTransform, B extends PipelineDestination>( source: A, transform1: T1, transform2: T2, transform3: T3, transform4: T4, destination: B, options?: PipelineOptions ): PipelinePromise; function __promisify__( streams: ReadonlyArray, options?: PipelineOptions ): Promise; function __promisify__( stream1: NodeJS.ReadableStream, stream2: NodeJS.ReadWriteStream | NodeJS.WritableStream, ...streams: Array, ): Promise; } interface Pipe { close(): void; hasRef(): boolean; ref(): void; unref(): void; } const promises: typeof streamPromises; } export = internal; }