Web Streams

ReadableStream.pipeThrough()

Connects a transform and returns its readable side. Consume the returned stream; transformation can otherwise wait for demand. Tested on Node.js 22.16.0. Example output (one line per entry): ["CAT true"].

Formal Syntax & Structure

nodejs syntaxnodejs
stream.pipeThrough(transform[, options])

Parameters & Attributes

NameTypeDescription
transformobjectReadable and writable pair.
optionsobjectPropagation controls.

Return Value

ReadableStream

Transformed output.

Working Example

Example Snippetnodejs
const s = new ReadableStream({ start(c) { c.enqueue('cat'); c.close(); } });const t = new TransformStream({ transform(v, c) { c.enqueue(v.toUpperCase()); } });const r = s.pipeThrough(t).getReader();try {    console.log((await r.read()).value, (await r.read()).done);}finally {    r.releaseLock();}
Node.js Reference