Web Streams

ReadableStream.pipeTo()

Transfers chunks to a writable stream while respecting its demand. Await completion to detect failures and cleanup. Tested on Node.js 22.16.0. Example output (one line per entry): ["2,4 false"].

Formal Syntax & Structure

nodejs syntaxnodejs
stream.pipeTo(destination[, options])

Parameters & Attributes

NameTypeDescription
destinationWritableStreamDestination.
optionsobjectSignal and propagation options.

Return Value

Promise<void>

Transfer completion.

Working Example

Example Snippetnodejs
const result = [];const s = new ReadableStream({ start(c) { c.enqueue(2); c.enqueue(4); c.close(); } });await s.pipeTo(new WritableStream({ write(v) { result.push(v); } }));console.log(result.join(','), s.locked);
Node.js Reference