push-stream-std

@push-stream-std/push-stream-base (0.0.4)

Published 2026-07-19 23:20:12 +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-stream-base@0.0.4
"@push-stream-std/push-stream-base": "0.0.4"

About this package

push-stream-base

Shared base classes and utilities for push-stream-std libraries.

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

Synopsis

import { createSource, createSink, createThrough, createDuplex } from '@push-stream-std/push-stream-base';

const source = createSource(function resume() {
  if (this.sink.paused) return;
  this.sink.write('ping');
  this.sink.end();
});

const sink = createSink(
  function write(data) { console.log('received', data); },
  function end(err) { console.log('done', err); }
);

source.pipe(sink);
import { createThrough, isSink, isSource } from '@push-stream-std/push-stream-base';

const mapper = createThrough(function write(data) {
  return data.toUpperCase();
});

isSource(source);  // true
isSink(sink);      // true

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-stream-base

Description

Implements the canonical push-stream patterns from Dominic Tarr's specification. Sources start paused: true, sinks start paused: false. The pipe() method connects streams and invokes resume() to initiate data flow. Through streams use a head pointer pattern with periodic compaction (splice(0, head) when head > 1024) for amortized O(1) buffer operations instead of the O(n) shift() approach.

API

createSource(onResume)

Creates a push-stream source.

  • onResume (this) => any – Called on each resume loop iteration. Returned values control flow:
    • false, null, or undefined – Stop the loop.
    • number – Return without further processing.
    • Any other value – Continue emitting.
  • Returns A source object with pipe(), resume(), abort(), sink, paused, and ended.

createSink(onWrite, onEnd)

Creates a push-stream sink.

  • onWrite (data) => void (optional) – Called with each written value.
  • onEnd (err) => void (optional) – Called on stream end. err is null for normal end, or the error for abort/error.
  • Returns A sink object with write(), end(), abort(), source, paused, and ended.

createThrough(onWrite, onEnd)

Creates a push-stream through (transform) stream.

  • onWrite (data) => any (optional) – Transforms incoming data. Return null or undefined to suppress the value.
  • onEnd (err) => void (optional) – Called on stream end.
  • Returns A through object with pipe(), write(), end(), abort(), resume(), source, sink, paused, and ended. Uses an internal buffer with head pointer compaction.

createDuplex(sourceFactory, sinkFactory)

Creates a push-stream duplex (independent source and sink, not internally connected).

  • sourceFactory () => source (optional) – Factory returning the source side.
  • sinkFactory () => sink (optional) – Factory returning the sink side.
  • Returns A duplex object with pipe(), resume(), abort(), source, sink, paused, ended, and resolve(actualDuplex) for deferred resolution.

isSink(obj)

Returns true if obj has write and end methods (type guard for sinks).

isSource(obj)

Returns true if obj has pipe and resume methods (type guard for sources).

Tests

npm test

Requirements

Node.js 18 or later. ESM only.

License

MIT

Keywords

push-stream stream base utilities
Details
npm
2026-07-19 23:20:12 +00:00
0
SEE LICENSE IN LICENSE
4.4 KiB
Assets (1)
Versions (6) 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.4 2026-07-19