https://github.com/roccomuso/batched-stream
Transform stream which batches a bunch of input data into groups of specified size (supporting objectMode).
https://github.com/roccomuso/batched-stream
batch byte chunks nodejs objectmode stream transform
Last synced: about 1 year ago
JSON representation
Transform stream which batches a bunch of input data into groups of specified size (supporting objectMode).
- Host: GitHub
- URL: https://github.com/roccomuso/batched-stream
- Owner: roccomuso
- Created: 2018-07-17T15:41:58.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-31T17:49:24.000Z (almost 8 years ago)
- Last Synced: 2024-04-24T00:44:07.101Z (about 2 years ago)
- Topics: batch, byte, chunks, nodejs, objectmode, stream, transform
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 9
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Batched Stream
[](https://travis-ci.org/roccomuso/batched-stream)
[](https://standardjs.com)
[](https://www.npmjs.com/package/batched-stream)

[](https://david-dm.org/roccomuso/batched-stream)
> Transform stream supporting objectMode, which batches a bunch of input data into groups of specified size and will emit arrays, so that you can deal with pieces of input asynchronously.
## Install
> npm install --save batched-stream
## Usage
```javascript
const BatchStream = require('batched-stream')
const batch = new BatchStream({
size : 5, // Bytes or N. of objects (when objectMode is true)
objectMode: true, // false by default
strictMode: false // return the rest of the batch when a stream contains a number of items that is not a strict multiply of the batch size
})
stream
.pipe(batch)
.pipe(new ArrayStream()) // In objectMode: true, deals with array input from pipe.
```
You can `.pipe` other streams to it or `.write` them yourself (if you `.write` don't forget to `.end`). The options are passed down to the transform stream (you can increase the `highWaterMark` for example).
- If `objectMode` is enabled the emitted batches are `Array` of length equal to `size`. Otherwise `Buffer` with byte `size`-length are emitted.
- The `strictMode: false` allows to get the rest of the batch when a stream contains a number of items that is not a strict multiply of the batch size.
## Test
> npm test
### Author
Rocco Musolino ([@roccomuso](https://twitter.com/roccomuso))
### License
MIT