Master ReadableStream, TransformStream, pipeThrough vs pipeTo, backpressure, and integration with the fetch API
0 / 5 completed
1 / 5
What does a ReadableStream represent?
ReadableStream: models a streaming source. You construct it with an underlying source object exposing start, pull, and cancel methods that call controller.enqueue(chunk) and controller.close(). Consumers read via stream.getReader() and reader.read(), or pipe it to a destination — enabling backpressure-aware processing of large or live data.
2 / 5
What is the role of a TransformStream?
TransformStream: has { writable, readable } pair. Its transform(chunk, controller) function processes each chunk and enqueues output. You typically do source.pipeThrough(transform).pipeTo(destination). Built-in examples include TextDecoderStream and CompressionStream, which transform bytes to text or compress data chunk by chunk.
3 / 5
How does pipeThrough differ from pipeTo?
pipeThrough vs pipeTo:readable.pipeThrough(transform) wires the readable into a transform and yields the transform's readable, so you can chain more stages. readable.pipeTo(writable) is terminal — it pumps into a sink and returns a promise resolving on completion. Both propagate backpressure and error signals automatically.
4 / 5
What does backpressure mean in the Streams API?
Backpressure: prevents a fast producer from overwhelming a slow consumer. Each stream has an internal queue with a high-water mark; controller.desiredSize goes negative when the queue is full, signalling the source to pause enqueuing. Piping honours this automatically, so memory stays bounded when streaming large data.
5 / 5
How do streams integrate with the fetch API?
fetch + streams:const reader = response.body.getReader() lets you process a download chunk by chunk (e.g. progress bars, streamed parsing). You can also pass a ReadableStream as a request body for streaming uploads. This avoids loading entire payloads into memory and powers things like streamed AI responses.