ReadableStream
The ReadableStream interface of the Streams API represents a readable stream of byte data. The Fetch API offers a concrete instance of a ReadableStream through the body property of a Response object.
Type Parameters
| Type Parameter | Default type |
|---|---|
R | any |
Methods
[asyncIterator]()
asyncIterator: ReadableStreamAsyncIterator<R>;
Parameters
| Parameter | Type |
|---|---|
options? | ReadableStreamIteratorOptions |
Returns
ReadableStreamAsyncIterator<R>
cancel()
cancel(reason?): Promise<void>;
The cancel() method of the ReadableStream interface returns a Promise that resolves when the stream is canceled.
Parameters
| Parameter | Type |
|---|---|
reason? | any |
Returns
Promise<void>
getReader()
Call Signature
getReader(options): ReadableStreamBYOBReader;
The getReader() method of the ReadableStream interface creates a reader and locks the stream to it. While the stream is locked, no other reader can be acquired until this one is released.
Parameters
| Parameter | Type |
|---|---|
options | { mode: "byob"; } |
options.mode | "byob" |
Returns
Call Signature
getReader(): ReadableStreamDefaultReader<R>;
Returns
ReadableStreamDefaultReader<R>
Call Signature
getReader(options?): ReadableStreamReader<R>;
Parameters
| Parameter | Type |
|---|---|
options? | ReadableStreamGetReaderOptions |
Returns
pipeThrough()
pipeThrough<T>(transform, options?): ReadableStream<T>;
The pipeThrough() method of the ReadableStream interface provides a chainable way of piping the current stream through a transform stream or any other writable/readable pair.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
transform | ReadableWritablePair<T, R> |
options? | StreamPipeOptions |
Returns
ReadableStream<T>
pipeTo()
pipeTo(destination, options?): Promise<void>;
The pipeTo() method of the ReadableStream interface pipes the current ReadableStream to a given WritableStream and returns a Promise that fulfills when the piping process completes successfully, or rejects if any errors were encountered.
Parameters
| Parameter | Type |
|---|---|
destination | WritableStream<R> |
options? | StreamPipeOptions |
Returns
Promise<void>
tee()
tee(): [ReadableStream<R>, ReadableStream<R>];
The tee() method of the ReadableStream interface tees the current readable stream, returning a two-element array containing the two resulting branches as new ReadableStream instances.
Returns
[ReadableStream<R>, ReadableStream<R>]
values()
values(options?): ReadableStreamAsyncIterator<R>;
Parameters
| Parameter | Type |
|---|---|
options? | ReadableStreamIteratorOptions |
Returns
ReadableStreamAsyncIterator<R>
Properties
locked
readonly locked: boolean;
The locked read-only property of the ReadableStream interface returns whether or not the readable stream is locked to a reader.