push-stream-std

@push-stream-std/push-tee (0.0.5)

Published 2026-07-19 23:32:17 +00:00 by Dvorak

Installation

@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm install @push-stream-std/push-tee@0.0.5
"@push-stream-std/push-tee": "0.0.5"

About this package

push-tee

Split a push-stream source into multiple branch sources, each delivering values to its own sink.

Published as @push-stream-std/push-tee.

Synopsis

import tee from '@push-stream-std/push-tee';

const branches = tee(source, 2);

branches[0].pipe(sinkA);
branches[1].pipe(sinkB);

source.resume();
import tee from '@push-stream-std/push-tee';

const sink1 = collect(null, function (err, result) { console.log('sink1', result); });
const sink2 = collect(null, function (err, result) { console.log('sink2', result); });

const stream = tee(source, [sink1, sink2]);

Install

npm config set @push-stream-std:registry https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm config set -- //hub.kl1.tenere.ai/api/packages/push-stream-std/npm/:_authToken "$PACKAGE_TOKEN"
npm install @push-stream-std/push-tee

Description

Splits a single push-stream source into multiple branch sources. When called with a count, it returns an array of branch sources; each can be independently piped to a sink. When called with an array of sinks, it returns the source stream directly and distributes values to each sink. Branches use per-branch buffers with a head pointer pattern for amortized O(1) dequeues. Values are buffered during initialization until all branches have sinks connected. All branches must end before the upstream source is released.

API

tee(source, countOrSinks)

Splits a source into multiple branches.

  • source object – A push-stream source with pipe(), resume(), abort().
  • countOrSinks number | sink[] – Either the number of branches to create, or an array of pre-existing sinks to distribute values to.
  • Returns When given a number: branch[] – an array of branch source objects, each with pipe(), resume(), write(), end(), abort(), sink, source, paused, ended. When given sinks: the source stream object with pipe(), write(), end(), abort(), resume(), sink, paused, ended.

Each branch source forwards values from the upstream and manages its own buffer. Aborting a branch aborts the upstream and all remaining branches.

Tests

npm test

Tests cover splitting into 2 branches, buffering for late-connecting branches, delivering end to all branches, abort propagation, multiple simultaneous connected sinks, edge cases (empty source, single branch, immediate end), and streaming high-volume data through multiple sinks.

Requirements

Node.js 18 or later. ESM only.

License

MIT

Keywords

push-stream stream tee split
Details
npm
2026-07-19 23:32:17 +00:00
0
SEE LICENSE IN LICENSE
4.8 KiB
Assets (1)
Versions (5) View all
0.0.8 2026-07-21
0.0.7 2026-07-20
0.0.6 2026-07-20
0.0.5 2026-07-19
0.0.3 2026-07-19