liveBook · Manning

pipeThrough

As explained in JavaScript in Depth

pipeThrough is a Web Streams method that connects a readable stream through a transform stream and returns the transform's readable side for further chaining.

pipeThrough() connects a Web ReadableStream to a TransformStream and returns the transform's readable side, allowing another stage to continue the chain. It also coordinates backpressure, propagates errors, and cleans up pipeline resources. section 10.4.4

A common failure occurs when a fetch() response is sent into a Node.js transform: fetch() exposes a Web Stream, while native Node.js HTTP APIs use Node.js streams. Convert at the boundary with Readable.fromWeb(), or remain in Web Streams and use pipeThrough(); repeated conversions add adaptation, buffering, scheduling, and performance costs. section 10.4.2 section 10.8

Chaining transforms

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

Prefer built-in piping over manual forwarding loops or extracted controllers. The built-in operations preserve backpressure and coordinated cleanup; manual pushing can defeat backpressure. Await the eventual pipeTo() promise so Web Stream failures surface as rejected promises rather than disappearing or becoming unhandled rejections. section 10.6.1 section 10.8

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

Shows the compact chaining pattern for placing multiple TransformStreams between a readable source and a writable destination. section 10.4.4

How JavaScript in Depth covers it

How deep it goes
Explains chaining, backpressure, cleanup, error propagation, and runtime boundaries, but defers transform implementation details.
Examples
Demonstrates chaining transformA and transformB before sending the resulting readable stream to a writable destination.
What it assumes
Assumes familiarity with readable, writable, and transform streams; distinguishes Web Streams from Node.js streams and async iterables.
What you can do after
Apply it via Web Streams to build chained transforms, preserve backpressure, and handle completion or failure through promises.
How it connects
Ties Web Streams to TransformStream, pipeTo(), backpressure, Node.js streams, async iterables, and promise-based error propagation.

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.