node:stream
Node-compatible streaming abstractions (Stream, Readable, Writable,
Duplex, Transform, PassThrough, pipeline, finished, compose).
Available in both vjs and vjs-lite runtimes. Enabled by default unless
--no-node-compat is passed.
import ... from "node:stream"
node-compat (enabled by default; disable with --no-node-compat)Example
Section titled “Example”import { PassThrough, pipeline } from "node:stream";
const pass = new PassThrough();pass.on("data", (chunk) => console.log(String(chunk)));pass.end("hello stream");pipelinev0.0.0-alpha.2finishedv0.0.0-alpha.2callback to be notified when stream is no longer readable, writable, or has errored or closed prematurely.composev0.0.0-alpha.2Duplex stream.addAbortSignalv0.0.0-alpha.2AbortSignal to stream so aborting destroys stream with an AbortError.isErroredv0.0.0-alpha.2true if stream has encountered an error.isReadablev0.0.0-alpha.2true if stream is readable and not yet ended/destroyed.isWritablev0.0.0-alpha.2true if stream is writable and not yet ended/destroyed.Streamv0.0.0-alpha.2Readablev0.0.0-alpha.2Writablev0.0.0-alpha.2Duplexv0.0.0-alpha.2Duplex stream implementing both Readable and Writable.Transformv0.0.0-alpha.2PassThroughv0.0.0-alpha.2Transform implementation passing input bytes or objects directly to output.AbortSignalLikev0.0.0-alpha.2addAbortSignal.StreamOptionsv0.0.0-alpha.2Readable, Writable, Duplex, and Transform.ReadableOptionsv0.0.0-alpha.2new Readable(options).WritableOptionsv0.0.0-alpha.2new Writable(options).DuplexOptionsv0.0.0-alpha.2new Duplex(options).TransformOptionsv0.0.0-alpha.2new Transform(options) and new PassThrough(options).FinishedOptionsv0.0.0-alpha.2finished().PipelineOptionsv0.0.0-alpha.2promises.pipeline().BlobLikev0.0.0-alpha.2Blob structural interface returned by stream.consumers.blob().StreamPromisesv0.0.0-alpha.2stream.promises (node:stream/promises).StreamConsumersv0.0.0-alpha.2stream.consumers (node:stream/consumers).Functions
Section titled “Functions”pipeline
Section titled “pipeline”export function pipeline(...streams: any[]): any;
Pipe an ordered sequence of streams together, propagating errors and invoking the trailing callback upon completion.
| Name | Type | Description |
|---|---|---|
...streams | any[] | Streams and transforms ending with a completion callback. |
any — The final destination stream.finished
Section titled “finished”export function finished(
stream: unknown,
callback: (err?: Error | null) => void,
): () => void;
export function finished(
stream: unknown,
options: FinishedOptions,
callback: (err?: Error | null) => void,
): () => void;
Register callback to be notified when stream is no longer readable,
writable, or has errored or closed prematurely.
finished(stream, callback)| Name | Type | Description |
|---|---|---|
stream | unknown | Stream to observe. |
callback | (err?: Error | null) => void | Completion callback (err?: Error | null) => void. |
() => void — Cleanup function removing the registered listeners.finished(stream, options, callback)Register callback with explicit options to be notified when stream finishes.
| Name | Type | Description |
|---|---|---|
stream | unknown | Stream to observe. |
options | FinishedOptions | Completion observation options. |
callback | (err?: Error | null) => void | Completion callback (err?: Error | null) => void. |
() => void — Cleanup function removing the registered listeners.compose
Section titled “compose”export function compose(...streams: any[]): Duplex;
Compose two or more streams or transform functions into a single Duplex stream.
| Name | Type | Description |
|---|---|---|
...streams | any[] | Ordered pipeline stages to compose. |
Duplex — Composed Duplex stream.addAbortSignal
Section titled “addAbortSignal”export function addAbortSignal<T extends Stream>(signal: AbortSignalLike, stream: T): T;
Attach an AbortSignal to stream so aborting destroys stream with an AbortError.
| Name | Type | Description |
|---|---|---|
signal | AbortSignalLike | Abort signal to observe. |
stream | T | Target stream to destroy on abort. |
T — The same stream instance.isErrored
Section titled “isErrored”export function isErrored(stream: unknown): boolean;
Return true if stream has encountered an error.
| Name | Type | Description |
|---|---|---|
stream | unknown | Stream instance to inspect. |
boolean — true if stream is in an errored state.isReadable
Section titled “isReadable”export function isReadable(stream: unknown): boolean;
Return true if stream is readable and not yet ended/destroyed.
| Name | Type | Description |
|---|---|---|
stream | unknown | Stream instance to inspect. |
boolean — true if stream is readable.isWritable
Section titled “isWritable”export function isWritable(stream: unknown): boolean;
Return true if stream is writable and not yet ended/destroyed.
| Name | Type | Description |
|---|---|---|
stream | unknown | Stream instance to inspect. |
boolean — true if stream is writable.Classes
Section titled “Classes”Stream
Section titled “Stream”export class Stream {
static readonly Stream: typeof Stream;
static readonly Readable: typeof Readable;
static readonly Writable: typeof Writable;
static readonly Duplex: typeof Duplex;
static readonly Transform: typeof Transform;
static readonly PassThrough: typeof PassThrough;
static readonly pipeline: typeof pipeline;
static readonly finished: typeof finished;
static readonly compose: typeof compose;
static readonly addAbortSignal: typeof addAbortSignal;
static readonly isErrored: typeof isErrored;
static readonly isReadable: typeof isReadable;
static readonly isWritable: typeof isWritable;
static readonly promises: StreamPromises;
static readonly consumers: StreamConsumers;
addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
removeAllListeners(eventName?: string | symbol): this;
setMaxListeners(n: number): this;
getMaxListeners(): number;
listeners(eventName: string | symbol): Array<(...args: any[]) => void>;
rawListeners(eventName: string | symbol): Array<(...args: any[]) => void>;
emit(eventName: string | symbol, ...args: any[]): boolean;
listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
eventNames(): Array<string | symbol>;
pipe<T extends { write(chunk: any, ...args: any[]): any; end(...args: any[]): any }>(
destination: T,
options?: { end?: boolean },
): T;
}
Base class for Node-compatible streams with event-emitter capabilities.
| Property | Type | Description | Since |
|---|---|---|---|
Stream static readonly | typeof Stream | Self-reference to Stream. | v0.0.0-alpha.2 |
Readable static readonly | typeof Readable | Readable stream class. | v0.0.0-alpha.2 |
Writable static readonly | typeof Writable | Writable stream class. | v0.0.0-alpha.2 |
Duplex static readonly | typeof Duplex | Duplex stream class. | v0.0.0-alpha.2 |
Transform static readonly | typeof Transform | Transform stream class. | v0.0.0-alpha.2 |
PassThrough static readonly | typeof PassThrough | PassThrough stream class. | v0.0.0-alpha.2 |
pipeline static readonly | typeof pipeline | Callback-based pipeline helper. | v0.0.0-alpha.2 |
finished static readonly | typeof finished | Callback-based finished helper. | v0.0.0-alpha.2 |
compose static readonly | typeof compose | Stream composition helper. | v0.0.0-alpha.2 |
addAbortSignal static readonly | typeof addAbortSignal | AbortSignal attachment helper. | v0.0.0-alpha.2 |
isErrored static readonly | typeof isErrored | Check whether a stream has errored. | v0.0.0-alpha.2 |
isReadable static readonly | typeof isReadable | Check whether a stream is readable. | v0.0.0-alpha.2 |
isWritable static readonly | typeof isWritable | Check whether a stream is writable. | v0.0.0-alpha.2 |
promises static readonly | StreamPromises | Promise-based stream helpers. | v0.0.0-alpha.2 |
consumers static readonly | StreamConsumers | Stream consumer helpers. | v0.0.0-alpha.2 |
Stream.addListener
Section titled “Stream.addListener”addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisStream.on
Section titled “Stream.on”on(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisStream.once
Section titled “Stream.once”once(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a one-time event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisStream.removeListener
Section titled “Stream.removeListener”removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
Remove an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisStream.off
Section titled “Stream.off”off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Alias for removeListener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisStream.removeAllListeners
Section titled “Stream.removeAllListeners”removeAllListeners(eventName?: string | symbol): this;
Remove all listeners or listeners for eventName.
| Name | Type | Description |
|---|---|---|
eventName optional | string | symbol | — |
thisStream.setMaxListeners
Section titled “Stream.setMaxListeners”setMaxListeners(n: number): this;
Set maximum listener count.
| Name | Type | Description |
|---|---|---|
n | number | — |
thisStream.getMaxListeners
Section titled “Stream.getMaxListeners”getMaxListeners(): number;
Get maximum listener count.
numberStream.listeners
Section titled “Stream.listeners”listeners(eventName: string | symbol): Array<(...args: any[]) => void>;
Return registered listeners for eventName.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
Array<(...args: any[]) => void>Stream.rawListeners
Section titled “Stream.rawListeners”rawListeners(eventName: string | symbol): Array<(...args: any[]) => void>;
Return raw listener wrappers for eventName.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
Array<(...args: any[]) => void>Stream.emit
Section titled “Stream.emit”emit(eventName: string | symbol, ...args: any[]): boolean;
Emit an event synchronously.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
...args | any[] | — |
booleanStream.listenerCount
Section titled “Stream.listenerCount”listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
Return listener count for eventName.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener optional | (...args: any[]) => void | — |
numberStream.prependListener
Section titled “Stream.prependListener”prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
Prepend an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisStream.prependOnceListener
Section titled “Stream.prependOnceListener”prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
Prepend a one-time event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisStream.eventNames
Section titled “Stream.eventNames”eventNames(): Array<string | symbol>;
Return all registered event names.
Array<string | symbol>Stream.pipe
Section titled “Stream.pipe”pipe<T extends { write(chunk: any, ...args: any[]): any; end(...args: any[]): any }>(
destination: T,
options?: { end?: boolean },
): T;
Pipe output from this stream into destination.
| Name | Type | Description |
|---|---|---|
destination | T | Target writable stream. |
options optional | { end?: boolean } | Optional { end } piping flag. |
T — destination for chaining.Readable
Section titled “Readable”export class Readable extends Stream {
readonly readable: boolean;
readonly readableEnded: boolean;
readonly readableFlowing: boolean | null;
readonly readableHighWaterMark: number;
readonly readableLength: number;
readonly readableObjectMode: boolean;
readonly destroyed: boolean;
readonly errored: Error | null;
readonly closed: boolean;
constructor(options?: ReadableOptions);
_read(size: number): void;
read(size?: number): any;
setEncoding(encoding: string): this;
pause(): this;
resume(): this;
isPaused(): boolean;
unpipe(destination?: Writable): this;
unshift(chunk: any, encoding?: string): void;
push(chunk: any, encoding?: string): boolean;
destroy(error?: Error): this;
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
static from(
iterable: Iterable<any> | AsyncIterable<any>,
options?: ReadableOptions,
): Readable;
static toWeb(streamReadable: Readable): unknown;
static fromWeb(readableStream: unknown, options?: ReadableOptions): Readable;
}
Node-compatible readable stream.
constructor(options?: ReadableOptions);
Construct a Readable stream.
| Name | Type | Description |
|---|---|---|
options optional | ReadableOptions | Optional stream configuration. |
| Property | Type | Description | Since |
|---|---|---|---|
readable readonly | boolean | Whether the stream is currently readable. | v0.0.0-alpha.2 |
readableEnded readonly | boolean | Whether "end" has been emitted. | v0.0.0-alpha.2 |
readableFlowing readonly | boolean | null | Current flowing mode state (null, true, or false). | v0.0.0-alpha.2 |
readableHighWaterMark readonly | number | Configured buffer high-water mark. | v0.0.0-alpha.2 |
readableLength readonly | number | Number of bytes or objects currently buffered. | v0.0.0-alpha.2 |
readableObjectMode readonly | boolean | Whether the stream operates in object mode. | v0.0.0-alpha.2 |
destroyed readonly | boolean | Whether destroy() has been called. | v0.0.0-alpha.2 |
errored readonly | Error | null | Error passed to destroy(err), or null. | v0.0.0-alpha.2 |
closed readonly | boolean | Whether "close" has been emitted. | v0.0.0-alpha.2 |
Readable._read
Section titled “Readable._read”_read(size: number): void;
Internal read hook overridden by subclasses.
| Name | Type | Description |
|---|---|---|
size | number | — |
voidReadable.read
Section titled “Readable.read”read(size?: number): any;
Pull up to size bytes/objects from the internal buffer.
| Name | Type | Description |
|---|---|---|
size optional | number | — |
anyReadable.setEncoding
Section titled “Readable.setEncoding”setEncoding(encoding: string): this;
Set character encoding used to decode emitted chunks.
| Name | Type | Description |
|---|---|---|
encoding | string | — |
thisReadable.pause
Section titled “Readable.pause”pause(): this;
Switch out of flowing mode and pause "data" events.
thisReadable.resume
Section titled “Readable.resume”resume(): this;
Switch into flowing mode and resume "data" events.
thisReadable.isPaused
Section titled “Readable.isPaused”isPaused(): boolean;
Return true if the stream is currently paused.
booleanReadable.unpipe
Section titled “Readable.unpipe”unpipe(destination?: Writable): this;
Detach one or all piped destinations.
| Name | Type | Description |
|---|---|---|
destination optional | Writable | — |
thisReadable.unshift
Section titled “Readable.unshift”unshift(chunk: any, encoding?: string): void;
Push chunk back to the front of the read queue.
| Name | Type | Description |
|---|---|---|
chunk | any | — |
encoding optional | string | — |
voidReadable.push
Section titled “Readable.push”push(chunk: any, encoding?: string): boolean;
Push chunk into the read queue (null signals EOF).
| Name | Type | Description |
|---|---|---|
chunk | any | — |
encoding optional | string | — |
booleanReadable.destroy
Section titled “Readable.destroy”destroy(error?: Error): this;
Destroy the stream and optionally emit "error".
| Name | Type | Description |
|---|---|---|
error optional | Error | — |
thisReadable.[Symbol.asyncIterator]
Section titled “Readable.[Symbol.asyncIterator]”[Symbol.asyncIterator](): AsyncIterableIterator<any>;
Iterate asynchronously over emitted chunks.
Readable.from
Section titled “Readable.from”static from(
iterable: Iterable<any> | AsyncIterable<any>,
options?: ReadableOptions,
): Readable;
Create a Readable stream from an iterable or async iterable.
| Name | Type | Description |
|---|---|---|
iterable | Iterable<any> | AsyncIterable<any> | — |
options optional | ReadableOptions | — |
Readable.toWeb
Section titled “Readable.toWeb”static toWeb(streamReadable: Readable): unknown;
Convert a Readable into a WHATWG ReadableStream.
| Name | Type | Description |
|---|---|---|
streamReadable | Readable | — |
unknownReadable.fromWeb
Section titled “Readable.fromWeb”static fromWeb(readableStream: unknown, options?: ReadableOptions): Readable;
Convert a WHATWG ReadableStream into a Node Readable.
| Name | Type | Description |
|---|---|---|
readableStream | unknown | — |
options optional | ReadableOptions | — |
Writable
Section titled “Writable”export class Writable extends Stream {
readonly writable: boolean;
readonly writableEnded: boolean;
readonly writableFinished: boolean;
readonly writableHighWaterMark: number;
readonly writableLength: number;
readonly writableObjectMode: boolean;
readonly writableCorked: number;
readonly destroyed: boolean;
readonly errored: Error | null;
readonly closed: boolean;
constructor(options?: WritableOptions);
_write(
chunk: any,
encoding: string,
callback: (error?: Error | null) => void,
): void;
write(chunk: any, callback?: (error?: Error | null) => void): boolean;
write(
chunk: any,
encoding: string,
callback?: (error?: Error | null) => void,
): boolean;
end(callback?: () => void): this;
end(chunk: any, callback?: () => void): this;
end(chunk: any, encoding: string, callback?: () => void): this;
cork(): void;
uncork(): void;
setDefaultEncoding(encoding: string): this;
destroy(error?: Error): this;
static toWeb(streamWritable: Writable): unknown;
static fromWeb(writableStream: unknown, options?: WritableOptions): Writable;
}
Node-compatible writable stream.
constructor(options?: WritableOptions);
Construct a Writable stream.
| Name | Type | Description |
|---|---|---|
options optional | WritableOptions | Optional stream configuration. |
| Property | Type | Description | Since |
|---|---|---|---|
writable readonly | boolean | Whether the stream is currently writable. | v0.0.0-alpha.2 |
writableEnded readonly | boolean | Whether end() has been called. | v0.0.0-alpha.2 |
writableFinished readonly | boolean | Whether "finish" has been emitted. | v0.0.0-alpha.2 |
writableHighWaterMark readonly | number | Configured buffer high-water mark. | v0.0.0-alpha.2 |
writableLength readonly | number | Number of bytes or objects currently queued for writing. | v0.0.0-alpha.2 |
writableObjectMode readonly | boolean | Whether the stream operates in object mode. | v0.0.0-alpha.2 |
writableCorked readonly | number | Nesting depth of cork() calls. | v0.0.0-alpha.2 |
destroyed readonly | boolean | Whether destroy() has been called. | v0.0.0-alpha.2 |
errored readonly | Error | null | Error passed to destroy(err), or null. | v0.0.0-alpha.2 |
closed readonly | boolean | Whether "close" has been emitted. | v0.0.0-alpha.2 |
Writable._write
Section titled “Writable._write”_write(
chunk: any,
encoding: string,
callback: (error?: Error | null) => void,
): void;
Internal write hook overridden by subclasses.
| Name | Type | Description |
|---|---|---|
chunk | any | — |
encoding | string | — |
callback | (error?: Error | null) => void | — |
voidWritable.write
Section titled “Writable.write”write(chunk: any, callback?: (error?: Error | null) => void): boolean;
write(
chunk: any,
encoding: string,
callback?: (error?: Error | null) => void,
): boolean;
Write chunk to the stream.
write(chunk, callback?)| Name | Type | Description |
|---|---|---|
chunk | any | — |
callback optional | (error?: Error | null) => void | — |
booleanwrite(chunk, encoding, callback?)Write chunk with explicit string encoding to the stream.
| Name | Type | Description |
|---|---|---|
chunk | any | — |
encoding | string | — |
callback optional | (error?: Error | null) => void | — |
booleanWritable.end
Section titled “Writable.end”end(callback?: () => void): this;
end(chunk: any, callback?: () => void): this;
end(chunk: any, encoding: string, callback?: () => void): this;
Signal that no more data will be written.
end(callback?)| Name | Type | Description |
|---|---|---|
callback optional | () => void | — |
thisend(chunk, callback?)Write a final chunk and close the writable stream.
| Name | Type | Description |
|---|---|---|
chunk | any | — |
callback optional | () => void | — |
thisend(chunk, encoding, callback?)Write a final chunk with encoding and close the writable stream.
| Name | Type | Description |
|---|---|---|
chunk | any | — |
encoding | string | — |
callback optional | () => void | — |
thisWritable.cork
Section titled “Writable.cork”cork(): void;
Buffer subsequent writes in memory until uncork() is called.
voidWritable.uncork
Section titled “Writable.uncork”uncork(): void;
Flush all writes buffered since cork().
voidWritable.setDefaultEncoding
Section titled “Writable.setDefaultEncoding”setDefaultEncoding(encoding: string): this;
Set the default string encoding for write().
| Name | Type | Description |
|---|---|---|
encoding | string | — |
thisWritable.destroy
Section titled “Writable.destroy”destroy(error?: Error): this;
Destroy the stream and optionally emit "error".
| Name | Type | Description |
|---|---|---|
error optional | Error | — |
thisWritable.toWeb
Section titled “Writable.toWeb”static toWeb(streamWritable: Writable): unknown;
Convert a Writable into a WHATWG WritableStream.
| Name | Type | Description |
|---|---|---|
streamWritable | Writable | — |
unknownWritable.fromWeb
Section titled “Writable.fromWeb”static fromWeb(writableStream: unknown, options?: WritableOptions): Writable;
Convert a WHATWG WritableStream into a Node Writable.
| Name | Type | Description |
|---|---|---|
writableStream | unknown | — |
options optional | WritableOptions | — |
Duplex
Section titled “Duplex”export class Duplex extends Readable {
readonly writable: boolean;
readonly writableEnded: boolean;
readonly writableFinished: boolean;
readonly writableHighWaterMark: number;
readonly writableLength: number;
readonly writableObjectMode: boolean;
readonly writableCorked: number;
allowHalfOpen: boolean;
constructor(options?: DuplexOptions);
_write(
chunk: any,
encoding: string,
callback: (error?: Error | null) => void,
): void;
write(chunk: any, callback?: (error?: Error | null) => void): boolean;
write(
chunk: any,
encoding: string,
callback?: (error?: Error | null) => void,
): boolean;
end(callback?: () => void): this;
end(chunk: any, callback?: () => void): this;
end(chunk: any, encoding: string, callback?: () => void): this;
cork(): void;
uncork(): void;
setDefaultEncoding(encoding: string): this;
static from(src: unknown): Duplex;
static toWeb(streamDuplex: Duplex): { readable: unknown; writable: unknown };
static fromWeb(
pair: { readable: unknown; writable: unknown },
options?: DuplexOptions,
): Duplex;
}
Node-compatible bidirectional Duplex stream implementing both Readable and Writable.
constructor(options?: DuplexOptions);
Construct a Duplex stream.
| Name | Type | Description |
|---|---|---|
options optional | DuplexOptions | Optional duplex stream configuration. |
| Property | Type | Description | Since |
|---|---|---|---|
writable readonly | boolean | Whether the writable side is currently writable. | v0.0.0-alpha.2 |
writableEnded readonly | boolean | Whether end() has been called. | v0.0.0-alpha.2 |
writableFinished readonly | boolean | Whether "finish" has been emitted. | v0.0.0-alpha.2 |
writableHighWaterMark readonly | number | Writable high-water mark. | v0.0.0-alpha.2 |
writableLength readonly | number | Queued bytes or objects on the writable side. | v0.0.0-alpha.2 |
writableObjectMode readonly | boolean | Whether the writable side operates in object mode. | v0.0.0-alpha.2 |
writableCorked readonly | number | Nesting depth of cork() calls. | v0.0.0-alpha.2 |
allowHalfOpen | boolean | Whether half-open mode is enabled. | v0.0.0-alpha.2 |
Duplex._write
Section titled “Duplex._write”_write(
chunk: any,
encoding: string,
callback: (error?: Error | null) => void,
): void;
Internal write hook overridden by subclasses.
| Name | Type | Description |
|---|---|---|
chunk | any | — |
encoding | string | — |
callback | (error?: Error | null) => void | — |
voidDuplex.write
Section titled “Duplex.write”write(chunk: any, callback?: (error?: Error | null) => void): boolean;
write(
chunk: any,
encoding: string,
callback?: (error?: Error | null) => void,
): boolean;
Write chunk to the writable side.
write(chunk, callback?)| Name | Type | Description |
|---|---|---|
chunk | any | — |
callback optional | (error?: Error | null) => void | — |
booleanwrite(chunk, encoding, callback?)Write chunk with explicit encoding to the writable side.
| Name | Type | Description |
|---|---|---|
chunk | any | — |
encoding | string | — |
callback optional | (error?: Error | null) => void | — |
booleanDuplex.end
Section titled “Duplex.end”end(callback?: () => void): this;
end(chunk: any, callback?: () => void): this;
end(chunk: any, encoding: string, callback?: () => void): this;
End the writable side of the duplex stream.
end(callback?)| Name | Type | Description |
|---|---|---|
callback optional | () => void | — |
thisend(chunk, callback?)Write a final chunk and end the writable side.
| Name | Type | Description |
|---|---|---|
chunk | any | — |
callback optional | () => void | — |
thisend(chunk, encoding, callback?)Write a final chunk with encoding and end the writable side.
| Name | Type | Description |
|---|---|---|
chunk | any | — |
encoding | string | — |
callback optional | () => void | — |
thisDuplex.cork
Section titled “Duplex.cork”cork(): void;
Buffer subsequent writes until uncork().
voidDuplex.uncork
Section titled “Duplex.uncork”uncork(): void;
Flush buffered writes.
voidDuplex.setDefaultEncoding
Section titled “Duplex.setDefaultEncoding”setDefaultEncoding(encoding: string): this;
Set the default string encoding for write().
| Name | Type | Description |
|---|---|---|
encoding | string | — |
thisDuplex.from
Section titled “Duplex.from”static from(src: unknown): Duplex;
Create a Duplex stream from a string, buffer, iterable, or stream pair.
| Name | Type | Description |
|---|---|---|
src | unknown | — |
Duplex.toWeb
Section titled “Duplex.toWeb”static toWeb(streamDuplex: Duplex): { readable: unknown; writable: unknown };
Convert a Duplex into a { readable, writable } WHATWG pair.
| Name | Type | Description |
|---|---|---|
streamDuplex | Duplex | — |
{ readable: unknown; writable: unknown }Duplex.fromWeb
Section titled “Duplex.fromWeb”static fromWeb(
pair: { readable: unknown; writable: unknown },
options?: DuplexOptions,
): Duplex;
Convert a { readable, writable } WHATWG pair into a Duplex.
| Name | Type | Description |
|---|---|---|
pair | { readable: unknown; writable: unknown } | — |
options optional | DuplexOptions | — |
Transform
Section titled “Transform”export class Transform extends Duplex {
constructor(options?: TransformOptions);
_transform(
chunk: any,
encoding: string,
callback: (error?: Error | null, data?: any) => void,
): void;
_flush(callback: (error?: Error | null, data?: any) => void): void;
}
Duplex stream whose output is computed from its input.
constructor(options?: TransformOptions);
Construct a Transform stream.
| Name | Type | Description |
|---|---|---|
options optional | TransformOptions | Optional transform hooks and stream configuration. |
Transform._transform
Section titled “Transform._transform”_transform(
chunk: any,
encoding: string,
callback: (error?: Error | null, data?: any) => void,
): void;
Internal transform hook overridden by subclasses.
| Name | Type | Description |
|---|---|---|
chunk | any | — |
encoding | string | — |
callback | (error?: Error | null, data?: any) => void | — |
voidTransform._flush
Section titled “Transform._flush”_flush(callback: (error?: Error | null, data?: any) => void): void;
Internal flush hook invoked before the readable side ends.
| Name | Type | Description |
|---|---|---|
callback | (error?: Error | null, data?: any) => void | — |
voidPassThrough
Section titled “PassThrough”export class PassThrough extends Transform {
constructor(options?: TransformOptions);
}
Trivial Transform implementation passing input bytes or objects directly to output.
constructor(options?: TransformOptions);
Construct a PassThrough stream.
| Name | Type | Description |
|---|---|---|
options optional | TransformOptions | Optional transform stream configuration. |
Interfaces
Section titled “Interfaces”AbortSignalLike
Section titled “AbortSignalLike”export interface AbortSignalLike {
readonly aborted: boolean;
readonly reason?: unknown;
addEventListener(type: string, listener: (...args: any[]) => void, options?: { once?: boolean }): void;
removeEventListener?(type: string, listener: (...args: any[]) => void): void;
}
Minimal abort-signal contract accepted by stream options and addAbortSignal.
| Property | Type | Description | Since |
|---|---|---|---|
aborted readonly | boolean | Whether the signal has already been aborted. | v0.0.0-alpha.2 |
reason readonly optional | unknown | Optional abort reason value. | v0.0.0-alpha.2 |
AbortSignalLike.addEventListener
Section titled “AbortSignalLike.addEventListener”addEventListener(type: string, listener: (...args: any[]) => void, options?: { once?: boolean }): void;
Register an "abort" listener.
| Name | Type | Description |
|---|---|---|
type | string | Event type ("abort"). |
listener | (...args: any[]) => void | Callback invoked on abort. |
options optional | { once?: boolean } | Optional listener options. |
voidAbortSignalLike.removeEventListener
Section titled “AbortSignalLike.removeEventListener”removeEventListener?(type: string, listener: (...args: any[]) => void): void;
Unregister an "abort" listener.
| Name | Type | Description |
|---|---|---|
type | string | Event type ("abort"). |
listener | (...args: any[]) => void | Callback to remove. |
voidStreamOptions
Section titled “StreamOptions”export interface StreamOptions<T = any> {
emitClose?: boolean;
highWaterMark?: number;
objectMode?: boolean;
autoDestroy?: boolean;
signal?: AbortSignalLike;
destroy?: (
this: T,
error: Error | null,
callback: (error?: Error | null) => void,
) => void;
construct?: (this: T, callback: (error?: Error | null) => void) => void;
}
Common stream options shared by Readable, Writable, Duplex, and Transform.
| Property | Type | Description | Since |
|---|---|---|---|
emitClose optional | boolean | Emit close automatically when destroyed (default true). | v0.0.0-alpha.2 |
highWaterMark optional | number | Buffer threshold before backpressure is signaled. | v0.0.0-alpha.2 |
objectMode optional | boolean | Enable object mode instead of byte/string mode. | v0.0.0-alpha.2 |
autoDestroy optional | boolean | Automatically destroy the stream after ending/finishing. | v0.0.0-alpha.2 |
signal optional | AbortSignalLike | Optional abort signal destroying the stream on abort. | v0.0.0-alpha.2 |
destroy optional | (
this: T,
error: Error | null,
callback: (error?: Error | null) => void,
) => void | Custom destroy() implementation. | v0.0.0-alpha.2 |
construct optional | (this: T, callback: (error?: Error | null) => void) => void | Custom construct() implementation. | v0.0.0-alpha.2 |
ReadableOptions
Section titled “ReadableOptions”export interface ReadableOptions extends StreamOptions<Readable> {
encoding?: string;
read?: (this: Readable, size: number) => void;
}
Options accepted by new Readable(options).
| Property | Type | Description | Since |
|---|---|---|---|
encoding optional | string | Default string encoding for decoded chunks. | v0.0.0-alpha.2 |
read optional | (this: Readable, size: number) => void | Custom _read(size) implementation. | v0.0.0-alpha.2 |
WritableOptions
Section titled “WritableOptions”export interface WritableOptions extends StreamOptions<Writable> {
decodeStrings?: boolean;
defaultEncoding?: string;
write?: (
this: Writable,
chunk: any,
encoding: string,
callback: (error?: Error | null) => void,
) => void;
writev?: (
this: Writable,
chunks: Array<{ chunk: any; encoding: string }>,
callback: (error?: Error | null) => void,
) => void;
final?: (this: Writable, callback: (error?: Error | null) => void) => void;
}
Options accepted by new Writable(options).
| Property | Type | Description | Since |
|---|---|---|---|
decodeStrings optional | boolean | Decode string arguments to Buffer before _write (default true). | v0.0.0-alpha.2 |
defaultEncoding optional | string | Default encoding for string chunks. | v0.0.0-alpha.2 |
write optional | (
this: Writable,
chunk: any,
encoding: string,
callback: (error?: Error | null) => void,
) => void | Custom _write(chunk, encoding, callback) implementation. | v0.0.0-alpha.2 |
writev optional | (
this: Writable,
chunks: Array<{ chunk: any; encoding: string }>,
callback: (error?: Error | null) => void,
) => void | Custom _writev(chunks, callback) batch write implementation. | v0.0.0-alpha.2 |
final optional | (this: Writable, callback: (error?: Error | null) => void) => void | Custom _final(callback) implementation invoked before finish. | v0.0.0-alpha.2 |
DuplexOptions
Section titled “DuplexOptions”export interface DuplexOptions
extends Omit<ReadableOptions, "construct" | "destroy">,
Omit<WritableOptions, "construct" | "destroy">
{
construct?(this: Duplex, callback: (error?: Error | null) => void): void;
destroy?(this: Duplex, error: Error | null, callback: (error?: Error | null) => void): void;
allowHalfOpen?: boolean;
readableHighWaterMark?: number;
writableHighWaterMark?: number;
readableObjectMode?: boolean;
writableObjectMode?: boolean;
}
Options accepted by new Duplex(options).
| Property | Type | Description | Since |
|---|---|---|---|
allowHalfOpen optional | boolean | Allow the readable side to stay open after the writable side ends (default true). | v0.0.0-alpha.2 |
readableHighWaterMark optional | number | High-water mark for the readable side. | v0.0.0-alpha.2 |
writableHighWaterMark optional | number | High-water mark for the writable side. | v0.0.0-alpha.2 |
readableObjectMode optional | boolean | Object mode for the readable side. | v0.0.0-alpha.2 |
writableObjectMode optional | boolean | Object mode for the writable side. | v0.0.0-alpha.2 |
DuplexOptions.construct
Section titled “DuplexOptions.construct”construct?(this: Duplex, callback: (error?: Error | null) => void): void;
Custom _construct(callback) hook invoked before I/O.
voidDuplexOptions.destroy
Section titled “DuplexOptions.destroy”destroy?(this: Duplex, error: Error | null, callback: (error?: Error | null) => void): void;
Custom _destroy(err, callback) implementation.
voidTransformOptions
Section titled “TransformOptions”export interface TransformOptions extends DuplexOptions {
transform?: (
this: Transform,
chunk: any,
encoding: string,
callback: (error?: Error | null, data?: any) => void,
) => void;
flush?: (
this: Transform,
callback: (error?: Error | null, data?: any) => void,
) => void;
}
Options accepted by new Transform(options) and new PassThrough(options).
| Property | Type | Description | Since |
|---|---|---|---|
transform optional | (
this: Transform,
chunk: any,
encoding: string,
callback: (error?: Error | null, data?: any) => void,
) => void | Custom _transform(chunk, encoding, callback) implementation. | v0.0.0-alpha.2 |
flush optional | (
this: Transform,
callback: (error?: Error | null, data?: any) => void,
) => void | Custom _flush(callback) implementation. | v0.0.0-alpha.2 |
FinishedOptions
Section titled “FinishedOptions”export interface FinishedOptions {
error?: boolean;
readable?: boolean;
writable?: boolean;
signal?: AbortSignalLike;
cleanup?: boolean;
}
Options accepted by finished().
| Property | Type | Description | Since |
|---|---|---|---|
error optional | boolean | Report stream errors (default true). | v0.0.0-alpha.2 |
readable optional | boolean | Observe readable completion on duplex streams. | v0.0.0-alpha.2 |
writable optional | boolean | Observe writable completion on duplex streams. | v0.0.0-alpha.2 |
signal optional | AbortSignalLike | Optional abort signal cancelling the listener. | v0.0.0-alpha.2 |
cleanup optional | boolean | Remove registered listeners on completion. | v0.0.0-alpha.2 |
PipelineOptions
Section titled “PipelineOptions”export interface PipelineOptions {
signal?: AbortSignalLike;
end?: boolean;
}
Options accepted by promises.pipeline().
| Property | Type | Description | Since |
|---|---|---|---|
signal optional | AbortSignalLike | Optional abort signal cancelling the pipeline. | v0.0.0-alpha.2 |
end optional | boolean | End the destination stream when the source finishes (default true). | v0.0.0-alpha.2 |
BlobLike
Section titled “BlobLike”export interface BlobLike {
readonly size: number;
readonly type: string;
arrayBuffer(): Promise<ArrayBuffer>;
bytes(): Promise<Uint8Array>;
text(): Promise<string>;
slice(start?: number, end?: number, contentType?: string): BlobLike;
}
Minimal Blob structural interface returned by stream.consumers.blob().
| Property | Type | Description | Since |
|---|---|---|---|
size readonly | number | Total size in bytes. | v0.0.0-alpha.2 |
type readonly | string | MIME media type string. | v0.0.0-alpha.2 |
BlobLike.arrayBuffer
Section titled “BlobLike.arrayBuffer”arrayBuffer(): Promise<ArrayBuffer>;
Read contents into an ArrayBuffer.
BlobLike.bytes
Section titled “BlobLike.bytes”bytes(): Promise<Uint8Array>;
Read contents into a Uint8Array.
BlobLike.text
Section titled “BlobLike.text”text(): Promise<string>;
Decode contents as UTF-8 text.
Promise<string>BlobLike.slice
Section titled “BlobLike.slice”slice(start?: number, end?: number, contentType?: string): BlobLike;
Return a sliced BlobLike.
| Name | Type | Description |
|---|---|---|
start optional | number | — |
end optional | number | — |
contentType optional | string | — |
StreamPromises
Section titled “StreamPromises”export interface StreamPromises {
pipeline(streams: readonly unknown[], options?: PipelineOptions): Promise<unknown>;
pipeline(...streams: unknown[]): Promise<unknown>;
finished(stream: unknown, options?: FinishedOptions): Promise<void>;
}
Promise-based stream helpers exposed as stream.promises (node:stream/promises).
StreamPromises.pipeline
Section titled “StreamPromises.pipeline”pipeline(streams: readonly unknown[], options?: PipelineOptions): Promise<unknown>;
pipeline(...streams: unknown[]): Promise<unknown>;
Pipe an array of streams and await completion.
pipeline(streams, options?)| Name | Type | Description |
|---|---|---|
streams | readonly unknown[] | — |
options optional | PipelineOptions | — |
Promise<unknown>pipeline(...streams)Pipe variadic stream stages and await completion.
| Name | Type | Description |
|---|---|---|
...streams | unknown[] | — |
Promise<unknown>StreamPromises.finished
Section titled “StreamPromises.finished”finished(stream: unknown, options?: FinishedOptions): Promise<void>;
Wait for a stream to finish, close, or error.
| Name | Type | Description |
|---|---|---|
stream | unknown | — |
options optional | FinishedOptions | — |
Promise<void>StreamConsumers
Section titled “StreamConsumers”export interface StreamConsumers {
arrayBuffer(stream: AsyncIterable<unknown> | { getReader(): unknown }): Promise<ArrayBuffer>;
blob(stream: AsyncIterable<unknown> | { getReader(): unknown }): Promise<BlobLike>;
buffer(stream: AsyncIterable<unknown> | { getReader(): unknown }): Promise<Uint8Array>;
bytes(stream: AsyncIterable<unknown> | { getReader(): unknown }): Promise<Uint8Array>;
json(stream: AsyncIterable<unknown> | { getReader(): unknown }): Promise<unknown>;
text(stream: AsyncIterable<unknown> | { getReader(): unknown }): Promise<string>;
}
Stream consumption helpers exposed as stream.consumers (node:stream/consumers).
StreamConsumers.arrayBuffer
Section titled “StreamConsumers.arrayBuffer”arrayBuffer(stream: AsyncIterable<unknown> | { getReader(): unknown }): Promise<ArrayBuffer>;
Consume stream into an ArrayBuffer.
| Name | Type | Description |
|---|---|---|
stream | AsyncIterable<unknown> | { getReader(): unknown } | — |
StreamConsumers.blob
Section titled “StreamConsumers.blob”blob(stream: AsyncIterable<unknown> | { getReader(): unknown }): Promise<BlobLike>;
Consume stream into a Blob.
| Name | Type | Description |
|---|---|---|
stream | AsyncIterable<unknown> | { getReader(): unknown } | — |
StreamConsumers.buffer
Section titled “StreamConsumers.buffer”buffer(stream: AsyncIterable<unknown> | { getReader(): unknown }): Promise<Uint8Array>;
Consume stream into a Buffer (Uint8Array).
| Name | Type | Description |
|---|---|---|
stream | AsyncIterable<unknown> | { getReader(): unknown } | — |
StreamConsumers.bytes
Section titled “StreamConsumers.bytes”bytes(stream: AsyncIterable<unknown> | { getReader(): unknown }): Promise<Uint8Array>;
Consume stream into a Uint8Array.
| Name | Type | Description |
|---|---|---|
stream | AsyncIterable<unknown> | { getReader(): unknown } | — |
StreamConsumers.json
Section titled “StreamConsumers.json”json(stream: AsyncIterable<unknown> | { getReader(): unknown }): Promise<unknown>;
Consume stream and parse JSON.
| Name | Type | Description |
|---|---|---|
stream | AsyncIterable<unknown> | { getReader(): unknown } | — |
Promise<unknown>StreamConsumers.text
Section titled “StreamConsumers.text”text(stream: AsyncIterable<unknown> | { getReader(): unknown }): Promise<string>;
Consume stream and decode UTF-8 text.
| Name | Type | Description |
|---|---|---|
stream | AsyncIterable<unknown> | { getReader(): unknown } | — |
Promise<string>Constants
Section titled “Constants”promises
Section titled “promises”export const promises: StreamPromises;
Promise-based stream utilities (node:stream/promises).
consumers
Section titled “consumers”export const consumers: StreamConsumers;
Stream consumer utilities (node:stream/consumers).
Default Export
Section titled “Default Export”default export
Section titled “default export”export default Stream;
Default export: the Stream base class with all stream constructors and helpers attached.
