JavaScript › Async Iterators & Streams
What's the difference between piping streams with pipeThrough() and pipeTo()?
AdvancedAnswer
pipeTo() sends a ReadableStream's data into a WritableStream and returns a Promise that resolves when piping finishes. pipeThrough() sends data through a TransformStream (readable + writable in one) and returns a new ReadableStream you can keep chaining or reading further.
const transformed = response.body
.pipeThrough(new TextDecoderStream())
.pipeThrough(new SomeTransform());
await transformed.pipeTo(writableStream);Real-world example Decoding, transforming, and compressing a file stream in one pipeline without buffering it all in memory.