@push-stream-std/push-batch (0.0.3)
Published 2026-07-19 21:13:53 +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-batch@0.0.3"@push-stream-std/push-batch": "0.0.3"About this package
push-batch
Batch multiple values into arrays by count or time.
Published as @push-stream-std/push-batch.
Synopsis
import batch from '@push-stream-std/push-batch';
const batched = batch(3);
source.pipe(batched).pipe(sink);
// Input: 1, 2, 3, 4, 5, 6, 7
// Output: [1,2,3], [4,5,6], [7]
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-batch
Description
A through stream that collects incoming values into arrays and flushes them when the batch reaches the given size or when an optional timeout fires. Useful for database writes, API calls, and logging where batching reduces overhead. On stream end, any remaining partial batch is flushed.
API
batch(size, timeoutOrOptions)
Creates a batching through stream.
- size
number– Number of values per batch. - timeoutOrOptions
number | object(optional) – Either a timeout in milliseconds as a number, or an options object:- timeout
number(optional) – Max wait time in ms before flushing a partial batch. - yieldEmpty
boolean(defaulttrue) – Whether to emit an empty array when the buffer is empty at flush time.
- timeout
- Returns A through stream with
pipe(),write(),end(),abort(),resume(),paused, andended.
Tests
npm test
Tests cover batching by count, partial batch emission on end, handling of empty sources, size=1 edge case, abort propagation, and the yieldEmpty option controlling empty batch emission.
Requirements
Node.js 18 or later. ESM only.
License
MIT
Keywords
push-stream
stream
batch