This Streams API interface provides a built-in byte length queuing strategy that can be used when constructing streams.
Node.js module
stream/web
The 'node:stream/web'
submodule implements WHATWG Streams API interfaces (ReadableStream
, WritableStream
) in Node.js, aligning with browser stream standards.
This allows interoperation between web-standard and Node-native streams in modern applications.
- const ReadableStream: {new (underlyingSource: UnderlyingByteSource, strategy?: QueuingStrategy<Uint8Array<ArrayBufferLike>>) => ReadableStream<Uint8Array<ArrayBufferLike>>; new (underlyingSource?: UnderlyingSource<R>, strategy?: QueuingStrategy<R>) => ReadableStream<R>}
- const ReadableStreamDefaultReader: new (stream: ReadableStream<R>) => ReadableStreamDefaultReader<R>
- const TransformStream: new (transformer?: Transformer<I, O>, writableStrategy?: QueuingStrategy<I>, readableStrategy?: QueuingStrategy<O>) => TransformStream<I, O>
- const WritableStream: new (underlyingSink?: UnderlyingSink<W>, strategy?: QueuingStrategy<W>) => WritableStream<W>
- const WritableStreamDefaultWriter: new (stream: WritableStream<W>) => WritableStreamDefaultWriter<W>
class CompressionStream
class DecompressionStream
Type definitions
interface CountQueuingStrategy
This Streams API interface provides a built-in byte length queuing strategy that can be used when constructing streams.
interface QueuingStrategy<T = any>
interface QueuingStrategyInit
- highWaterMark: number
Creates a new ByteLengthQueuingStrategy with the provided high water mark.
Note that the provided high water mark will not be validated ahead of time. Instead, if it is negative, NaN, or not a number, the resulting ByteLengthQueuingStrategy will cause the corresponding stream constructor to throw.
interface QueuingStrategySize<T = any>
interface ReadableByteStreamController
interface ReadableByteStreamControllerCallback
interface ReadableStream<R = any>
This Streams API interface represents a readable stream of byte data.
interface ReadableStreamAsyncIterator<T>
interface ReadableStreamBYOBReader
- view: T,options?: { min: number }
interface ReadableStreamBYOBRequest
interface ReadableStreamDefaultController<R = any>
interface ReadableStreamDefaultReader<R = any>
interface ReadableStreamErrorCallback
interface ReadableStreamGenericReader
interface ReadableStreamGetReaderOptions
- mode?: 'byob'
Creates a ReadableStreamBYOBReader and locks the stream to the new reader.
This call behaves the same way as the no-argument variant, except that it only works on readable byte streams, i.e. streams which were constructed specifically with the ability to handle "bring your own buffer" reading. The returned BYOB reader provides the ability to directly read individual chunks from the stream via its read() method, into developer-supplied buffers, allowing more precise control over allocation.
interface ReadableStreamReadDoneResult<T>
interface ReadableStreamReadValueResult<T>
interface ReadableWritablePair<R = any, W = any>
- writable: WritableStream<W>
Provides a convenient, chainable way of piping this readable stream through a transform stream (or any other { writable, readable } pair). It simply pipes the stream into the writable side of the supplied pair, and returns the readable side for further use.
Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
interface StreamPipeOptions
- preventClose?: boolean
Pipes this readable stream to a given writable stream destination. The way in which the piping process behaves under various error conditions can be customized with a number of passed options. It returns a promise that fulfills when the piping process completes successfully, or rejects if any errors were encountered.
Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
Errors and closures of the source and destination streams propagate as follows:
An error in this source readable stream will abort destination, unless preventAbort is truthy. The returned promise will be rejected with the source's error, or with any error that occurs during aborting the destination.
An error in destination will cancel this source readable stream, unless preventCancel is truthy. The returned promise will be rejected with the destination's error, or with any error that occurs during canceling the source.
When this source readable stream closes, destination will be closed, unless preventClose is truthy. The returned promise will be fulfilled once this process completes, unless an error is encountered while closing the destination, in which case it will be rejected with that error.
If destination starts out closed or closing, this source readable stream will be canceled, unless preventCancel is true. The returned promise will be rejected with an error indicating piping to a closed stream failed, or with any error that occurs during canceling the source.
The signal option can be set to an AbortSignal to allow aborting an ongoing pipe operation via the corresponding AbortController. In this case, this source readable stream will be canceled, and destination aborted, unless the respective options preventCancel or preventAbort are set.
interface TextDecoderOptions
interface TextDecoderStream
interface TextEncoderStream
interface Transformer<I = any, O = any>
interface TransformerFlushCallback<O>
interface TransformerStartCallback<O>
interface TransformerTransformCallback<I, O>
interface TransformStream<I = any, O = any>
interface TransformStreamDefaultController<O = any>
interface UnderlyingSink<W = any>
interface UnderlyingSinkAbortCallback
interface UnderlyingSinkCloseCallback
interface UnderlyingSinkStartCallback
interface UnderlyingSinkWriteCallback<W>
interface UnderlyingSource<R = any>
interface UnderlyingSourceCancelCallback
interface UnderlyingSourcePullCallback<R>
interface UnderlyingSourceStartCallback<R>
interface WritableStream<W = any>
This Streams API interface provides a standard abstraction for writing streaming data to a destination, known as a sink. This object comes with built-in back pressure and queuing.
interface WritableStreamDefaultController
This Streams API interface represents a controller allowing control of a WritableStream's state. When constructing a WritableStream, the underlying sink is given a corresponding WritableStreamDefaultController instance to manipulate.
interface WritableStreamDefaultWriter<W = any>
This Streams API interface is the object returned by WritableStream.getWriter() and once created locks the < writer to the WritableStream ensuring that no other streams can write to the underlying sink.
- type BufferSource = ArrayBufferView | ArrayBuffer
- type ReadableStreamController<T> = ReadableStreamDefaultController<T>
- type ReadableStreamReaderMode = 'byob'