Skip to content
Eugene Lazutkin edited this page May 19, 2026 · 3 revisions

Dashboard

Node.js CI NPM version

About

stream-fork is a toolkit of 1→N stream combinators — Writable streams that distribute every chunk to N downstream Writables under different dispatch shapes, with proper backpressure handling. Three primitives cover the three useful control-flow shapes; a small set of picker helpers compose with route into common load-balance, shard, and routing patterns.

stream-fork has zero runtime dependencies. It is a sibling to stream-join (N→1) and stream-json in the stream-chain family. Distributed under the New BSD license.

Documentation

Main components

  • fork — broadcast: every chunk to every live output; the slowest gates upstream. The default export — require('stream-fork') returns this.
  • route — single-target dispatch: a per-chunk pick(chunk, encoding) selects exactly one output.
  • filter — subset broadcast: one predicate per output decides whether that output receives the chunk.

Helpers

Other

Installation

npm i stream-fork

Quick example

const fork = require('stream-fork');
const fs = require('node:fs');
const zlib = require('node:zlib');

const gzip = zlib.createGzip();
gzip.pipe(fs.createWriteStream('log.txt.gz'));

// push every chunk to both the gzip chain and stdout
dataSource.pipe(fork([gzip, process.stdout]));

Engines

  • Node.js 22+.
  • Bun and Deno are tested via the tape-six test suite (npm run test:bun, npm run test:deno).

Clone this wiki locally