@push-stream-std/push-zip (0.0.7)
Installation
@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/npm install @push-stream-std/push-zip@0.0.7"@push-stream-std/push-zip": "0.0.7"About this package
@push-stream-std/push-zip
Combine N push-stream sources into arrays (N-tuples) by pairing corresponding values.
Published as @push-stream-std/push-zip.
Synopsis
import zip from '@push-stream-std/push-zip';
import pushable from '@push-stream-std/push-pushable';
const sourceA = pushable();
const sourceB = pushable();
const zipped = zip([sourceA, sourceB]);
const sink = {
paused: false,
write(v) { console.log(v); },
end() { console.log('done'); }
};
zipped.pipe(sink);
sourceA.push('a');
sourceB.push(1);
// Output: ['a', 1]
sourceA.push('b');
sourceB.push(2);
// Output: ['b', 2]
sourceA.end();
sourceB.end();
// Output: done
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-zip
Why
A source-like stream that subscribes to multiple upstream sources and emits arrays by pairing the next value from each source. Values are buffered per source until all sources have at least one available value, at which point a tuple is emitted. When any source ends without more buffered values, the zipped stream also ends. A single source is wrapped into single-element arrays. An empty sources array produces an immediately-ending stream. Per-source buffers use head pointer patterns for amortized O(1) dequeue.
API
zip(sources)
Creates a zip stream.
- sources
Array– An array of push-stream source objects. Non-array inputs are wrapped in a single-element array. - Returns A stream with
pipe(),write(),end(),abort(),resume(),paused, andended. Acts as a sink wrapper for each source and as a source for the downstream.
Tests
npm test
Tests cover synchronous tuple pairing, staggered source emission, source ending (short and balanced), single source wrapping, empty sources array, error propagation, and abort cleanup.
Requirements
Node.js 22 or later. ESM only.