method

ReadableStream.pipeThrough

Referenced types

interface ReadableWritablePair<R = any, W = any>

A { readable, writable } pair, such as a transform stream.

pipeThrough() pipes the source stream into the pair's writable side and returns the readable side for further use. Piping locks the source stream for the duration of the pipe, preventing any other consumer from acquiring a reader.

  • 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

Options that control how piping behaves under errors and closure.

Piping a stream locks 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 the source readable stream aborts the destination, unless preventAbort is truthy. The returned promise rejects with the source's error, or with any error that occurs while aborting the destination.

An error in the destination cancels the source readable stream, unless preventCancel is truthy. The returned promise rejects with the destination's error, or with any error that occurs while canceling the source.

When the source readable stream closes, the destination is closed, unless preventClose is truthy. The returned promise fulfills once this process completes, unless an error occurs while closing the destination, in which case it rejects with that error.

If the destination starts out closed or closing, the source readable stream is canceled, unless preventCancel is true. The returned promise rejects with an error indicating piping to a closed stream failed, or with any error that occurs while canceling the source.

signal can be set to an AbortSignal to abort an ongoing pipe operation with the corresponding AbortController. In this case, the source readable stream is canceled and the destination aborted, unless preventCancel or preventAbort is set.

  • preventAbort?: boolean
  • preventCancel?: boolean
  • 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.

class ReadableStream<R = any>

This Streams API interface 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.

MDN Reference