push-stream-std

@push-stream-std/push-abortable (0.0.12)

Published 2026-07-21 16:50:14 +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-abortable@0.0.12
"@push-stream-std/push-abortable": "0.0.12"

About this package

@push-stream-std/push-abortable

A through stream that can be aborted externally.

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

Synopsis

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

const stream = abortable((endErr) => {
  if (endErr) console.error('stream aborted', endErr);
  else console.log('stream ended normally');
});

source.pipe(stream).pipe(sink);

// External abort propagates through the pipeline
stream.abort(new Error('cancelled'));

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-abortable

Why

A through stream that wraps a push-stream pipeline and exposes an abort() method that propagates cancellation both upstream (via source.abort()) and downstream (via sink.end()). It accepts an optional onEnd callback notified on stream termination and an optional onSource callback that fires when an upstream source is piped in. The stream uses a head pointer pattern for amortized O(1) buffer operations.

API

abortable(onEnd, onSource)

Creates an abortable through stream.

  • onEnd (err) => void (optional) – Called when the stream terminates. Receives null for normal end or the error on abort/error.
  • onSource (source) => void (optional) – Called when an upstream source is connected via pipe().
  • Returns A stream object with pipe(), write(), end(), abort(), resume(), paused, ended, _source, and _sink properties.

Tests

npm test

Tests cover basic operations (creation, data passthrough, abort exposure), abort behavior (source abort propagation, sink end notification, idempotent aborts, abort after end), passthrough of normal end and errors, paused state tracking, edge cases (abort during write, cleanup after abort/end), and onEnd callback invocation for normal end, error end, and true end.

Requirements

Node.js 22 or later. ESM only.

Dependencies

Dependencies

ID Version
@push-stream-std/push-stream-base *

Development Dependencies

ID Version
fast-check ^4.5.3

Keywords

push-stream stream abortable
Details
npm
2026-07-21 16:50:14 +00:00
0
SEE LICENSE IN LICENSE
4.0 KiB
Assets (1)
Versions (10) View all
0.0.13 2026-07-21
0.0.12 2026-07-21
0.0.11 2026-07-21
0.0.10 2026-07-21
0.0.9 2026-07-20