Web APIs
ReadableStream.pipeThrough()
Pipe into the writable side of a transform and return its readable side. Consume the result to allow the pipeline to progress. Example console output: 6.
Formal Syntax & Structure
javascript syntaxjavascript
stream.pipeThrough(transform[, options])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| transform | ReadableWritablePair | Writable input and readable output. |
| options | object | Pipe options such as signal and propagation controls. |
Return Value
ReadableStream
Transform output stream.
Working Example
Example Snippetjavascript
(async () => {const source=new ReadableStream({start(c){c.enqueue(3);c.close()}}); const doubled=source.pipeThrough(new TransformStream({transform(x,c){c.enqueue(x*2)}})); const reader=doubled.getReader(); console.log((await reader.read()).value); await reader.read(); reader.releaseLock();})()