Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ReadableStream<R>

A readable stream represents a source of data, from which you can read.

Type parameters

  • R = any

Hierarchy

  • ReadableStream

Index

Constructors

constructor

Properties

[Symbol.asyncIterator]

[Symbol.asyncIterator]: (options?: ReadableStreamIteratorOptions) => ReadableStreamAsyncIterator<R>

{@inheritDoc ReadableStream.values}

Type declaration

Accessors

locked

  • get locked(): boolean
  • Whether or not the readable stream is locked to a reader.

    Returns boolean

Methods

cancel

  • cancel(reason?: any): Promise<void>
  • Cancels the stream, signaling a loss of interest in the stream by a consumer.

    The supplied reason argument will be given to the underlying source's cancel() method, which might or might not use it.

    Parameters

    • Optional reason: any

    Returns Promise<void>

getReader

  • 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.

    Parameters

    • __namedParameters: { mode: "byob" }
      • mode: "byob"

    Returns ReadableStreamBYOBReader

  • Creates a ReadableStreamDefaultReader and locks the stream to the new reader. While the stream is locked, no other reader can be acquired until this one is released.

    This functionality is especially useful for creating abstractions that desire the ability to consume a stream in its entirety. By getting a reader for the stream, you can ensure nobody else can interleave reads with yours or cancel the stream, which would interfere with your abstraction.

    Returns ReadableStreamDefaultReader<R>

pipeThrough

  • 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.

    Type parameters

    • T

    Parameters

    Returns ReadableStream<T>

pipeTo

  • Pipes this readable stream to a given writable stream. 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.

    Parameters

    Returns Promise<void>

tee

  • Tees this readable stream, returning a two-element array containing the two resulting branches as new ReadableStream instances.

    Teeing a stream will lock it, preventing any other consumer from acquiring a reader. To cancel the stream, cancel both of the resulting branches; a composite cancellation reason will then be propagated to the stream's underlying source.

    Note that the chunks seen in each branch will be the same object. If the chunks are not immutable, this could allow interference between the two branches.

    Returns [ReadableStream<R>, ReadableStream<R>]

values

  • Asynchronously iterates over the chunks in the stream's internal queue.

    Asynchronously iterating over the stream will lock it, preventing any other consumer from acquiring a reader. The lock will be released if the async iterator's return() method is called, e.g. by breaking out of the loop.

    By default, calling the async iterator's return() method will also cancel the stream. To prevent this, use the stream's values() method, passing true for the preventCancel option.

    Parameters

    Returns ReadableStreamAsyncIterator<R>

Generated using TypeDoc