Web APIs

ReadableStream.pipeThrough()

Try the free JavaScript compiler

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

NameTypeDescription
transformReadableWritablePairWritable input and readable output.
optionsobjectPipe 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();})()
JavaScript Reference