push-stream-std

@push-stream-std/push-zip (0.0.9)

Published 2026-07-21 15:54:03 +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-zip@0.0.9
"@push-stream-std/push-zip": "0.0.9"

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, and ended. 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.

Keywords

push-stream stream zip tuple combine
Details
npm
2026-07-21 15:54:03 +00:00
0
SEE LICENSE IN LICENSE
latest
4.2 KiB
Assets (1)
Versions (6) View all
0.0.9 2026-07-21
0.0.8 2026-07-21
0.0.7 2026-07-20
0.0.6 2026-07-20
0.0.5 2026-07-19