-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Eugene Lazutkin edited this page May 19, 2026
·
3 revisions
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.
-
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.
-
utils (pickRoundRobin, pickByHash, pickByKey, pickFirstMatch) — picker factories under
stream-fork/utils/that compose withrouteto express round-robin load balance, stable hash sharding, explicit key→index routing, and priority routing with catch-all.
- Release notes — detailed change history.
npm i stream-forkconst 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]));- Node.js 22+.
- Bun and Deno are tested via the
tape-sixtest suite (npm run test:bun,npm run test:deno).