push-stream-std

@push-stream-std/push-batch (0.0.7)

Published 2026-07-20 21:35:43 +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.7
"@push-stream-std/push-batch": "0.0.7"

About this package

@push-stream-std/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

Why

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 (default true) – Whether to emit an empty array when the buffer is empty at flush time.
  • Returns A through stream with pipe(), write(), end(), abort(), resume(), paused, and ended.

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 22 or later. ESM only.

Keywords

push-stream stream batch
Details
npm
2026-07-20 21:35:43 +00:00
0
SEE LICENSE IN LICENSE
3.5 KiB
Assets (1)
Versions (7) 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