liveBook · Manning

pipeTo

As explained in JavaScript in Depth

A Web Streams API method that pipes a readable stream to a writable destination and returns a promise when the operation completes.

A Web Streams API method that terminates a pipeline at a WritableStream. It returns a promise that resolves when piping completes, while managing backpressure, propagating errors, and cleaning up resources. section 10.4.4

const transformed = readable
  .pipeThrough(transformA)
  .pipeThrough(transformB);
 
await transformed.pipeTo(writable);

Chain transformations with pipeThrough(), then await pipeTo() at the destination. section 10.4.4

The operational rules are:

  • Treat the returned promise as the pipeline's completion and error boundary; an underlying source failure becomes a rejected promise. section 10.6.1
  • Prefer built-in piping over manual forwarding: it coordinates producer and consumer speed across the buffers in the chain. section 10.3.3 section 10.8
  • Keep a pipeline in one stream model when practical; crossing Node.js streams, Web Streams, and async iterables adds buffers, adapters, and scheduling overhead. section 10.8

A transformed Web Streams pipeline

const transformed = readable .pipeThrough(transformA) .pipeThrough(transformB); await transformed.pipeTo(writable); section 10.4.4

How JavaScript in Depth covers it

How deep it goes
Explains backpressure, cleanup, and rejected-promise errors, but does not detail the API's option parameters.
Examples
Uses chained pipeThrough() transformations followed by await transformed.pipeTo(writable).
What it assumes
Assumes familiarity with readable and writable streams, transformations, and promises.
What you can do after
Operate/configure a Web Streams pipeline while preserving automatic backpressure, error propagation, and resource cleanup.
How it connects
Connects Web Streams with pipeThrough(), TransformStream, WritableStream, backpressure, and promise rejection.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.