@push-stream-std/push-abortable (0.0.12)
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. Receivesnullfor normal end or the error on abort/error. - onSource
(source) => void(optional) – Called when an upstream source is connected viapipe(). - Returns A stream object with
pipe(),write(),end(),abort(),resume(),paused,ended,_source, and_sinkproperties.
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 |