https://github.com/remko/buffering-object-stream
Buffer Node Object Streams
https://github.com/remko/buffering-object-stream
Last synced: 10 months ago
JSON representation
Buffer Node Object Streams
- Host: GitHub
- URL: https://github.com/remko/buffering-object-stream
- Owner: remko
- Created: 2015-09-01T21:11:22.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-11-24T19:03:53.000Z (over 10 years ago)
- Last Synced: 2025-08-09T02:47:43.049Z (10 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# [buffering-object-stream: Buffer Node Object Streams](https://el-tramo.be/buffering-object-stream)
Adding a buffering input stream in your pipeline will collect a given number of objects,
and send them through as an array to the next stage. This is useful if you have a stream
source that emits objects, and you want to batch them together before sending them to a
database.
## Installation
npm install buffering-object-stream --save
## Usage
For example:
var through = require("through2");
vor bufferingObjectStream = require("buffering-object-stream");
createSomeObjectStream()
.pipe(bufferingObjectStream(4))
.pipe(through.obj(function (objects, enc, cb) {
console.log("Got objects: ", objects);
cb();
});
If `createObjectStream` sends out 10 objects (e.g. strings), this will print
out something like:
Got objects: ["object1", "object2", "object3", "object4"]
Got objects: ["object5", "object6", "object7", "object8"]
Got objects: ["object9", "object10"]
## API
### `bufferingObjectSream(bufferSize)`
- **`bufferSize`** - *integer*
The number of objects to buffer before emitting.