UNPKG

readable-web-to-node-stream

Version:

Converts a Web-API readable-stream into a Node.js readable-stream.

46 lines (45 loc) 1.78 kB
import type { Readable as UserLandReadable } from 'readable-stream'; import type { Readable as NodeReadable } from 'node:stream'; export interface ReadableWebToNodeStreamOptions { propagateDestroy: boolean; } /** * A hybrid implementation that converts a Web-API ReadableStream * into a Node.js Readable stream. * * Node.js Readable docs: https://nodejs.org/api/stream.html#stream_readable_streams * Web API ReadableStream docs: https://developer.mozilla.org/docs/Web/API/ReadableStream */ export declare class CommonReadableWebToNodeStream { private options; /** Total bytes pushed to the Node.js stream. */ bytesRead: number; /** Flag indicating that the stream has been released/closed. */ released: boolean; /** Holds the currently pending read, if any. */ private pendingRead; /** The underlying Web-API stream reader. */ private reader; /** * @param stream The Web-API ReadableStream to be wrapped. * @param options Options: `{propagateDestroy: boolean}` */ constructor(stream: ReadableStream<Uint8Array> | ReadableStream, options?: ReadableWebToNodeStreamOptions); /** * Should be bound to the Node.js Readable._read() method. * This method pushes data into the Node stream's internal queue. * * @param nodeReadable The Node.js stream instance. */ read(nodeReadable: NodeReadable | UserLandReadable): void; /** * Closes the stream and releasing the underlying stream lock. * Implementation is Readable._destroy() */ destroy(error: Error | null, callback: (error?: Error | null) => void): void; /** * Marks the stream as released, waits for pending operations, * and releases the underlying reader lock. */ private release; }