node:stream

Readable, Writable, Duplex, Transform, and composition helpers.

Elide exports Readable, Writable, Duplex, Transform, and PassThrough. The verified example below covers Readable.from, custom Transform and Writable hooks, and Promise-based pipeline completion.

Pipeline example

Use node:stream/promises when awaiting pipeline:

import { Readable, Transform, Writable } from "node:stream";
import { pipeline } from "node:stream/promises";

const output = [];
const source = Readable.from(["a", "b"]);
const upper = new Transform({
  transform(chunk, _encoding, callback) {
    callback(null, String(chunk).toUpperCase());
  },
});
const sink = new Writable({
  write(chunk, _encoding, callback) {
    output.push(String(chunk));
    callback();
  },
});

await pipeline(source, upper, sink);
console.log(output.join("")); // AB

pipeline and finished from node:stream use callback-style signatures. Their Promise-returning forms are exported by node:stream/promises.

Additional surface

  • Readable.from, Readable.wrap, and async iteration
  • Promise consumers such as toArray, forEach, some, every, find, and reduce
  • stream transformers such as map, filter, flatMap, drop, and take
  • compose, addAbortSignal, state predicates, and high-water-mark helpers
  • node:stream/iter, an Elide extension with iterator conversion helpers

See the Node.js stream documentation for the standard class and hook signatures.