Web Streams

new TransformStream()

Connects a writable input to a readable output through a transformation. Concurrently consume output to allow backpressure to resolve. Tested on Node.js 22.16.0. Example output (one line per entry): ["12", "true"].

Formal Syntax & Structure

nodejs syntaxnodejs
new TransformStream([transformer[, writableStrategy[, readableStrategy]]])

Parameters & Attributes

NameTypeDescription
transformerobjectTransform callbacks.
writableStrategyobjectInput queue strategy.
readableStrategyobjectOutput queue strategy.

Return Value

TransformStream

Connected pair.

Working Example

Example Snippetnodejs
const t = new TransformStream({ transform(n, c) { c.enqueue(n * 2); } });const w = t.writable.getWriter();const r = t.readable.getReader();try {    const writing = w.write(6);    console.log((await r.read()).value);    await writing;    const closing = w.close();    console.log((await r.read()).done);    await closing;}finally {    w.releaseLock();    r.releaseLock();}
Node.js Reference