transform-clump
Version:
A transform stream that returns clumps of data.
59 lines (40 loc) • 1.4 kB
Markdown
# transform-clump
[](https://travis-ci.org/tanem/transform-clump)
[](https://coveralls.io/r/tanem/transform-clump)
[](http://badge.fury.io/js/transform-clump)
A transform stream that clumps data into an array of a specified size. The oldest items in the array are replaced by the newer items as they stream in.
## Installation
```sh
$ npm install transform-clump --save
```
## Example
```js
var stream = require('stream');
var clump = require('transform-clump');
var source = stream.PassThrough({ objectMode: true });
var dest = stream.PassThrough({ objectMode: true });
var result;
source.pipe(clump(5)).pipe(dest);
dest.on('data', function(chunk){
result = chunk;
});
dest.on('end', function(){
// => [ { foo: 5 }, { foo: 1 }, { foo: 2 }, { foo: 3 }, { foo: 4 } ]
console.log(result);
});
for (var i = 0, j = 5; i < j; i++) source.push({ foo: i });
source.end({ foo: i });
```
## API
### var clump = transformClump(size)
Initialise a new `TransformClump` with the given `size`.
## Testing
```sh
$ make test
```
To generate a coverage report:
```sh
$ make test-cov
```
## Credits
* [urlgrey](https://github.com/cainus/urlgrey) for the Makefile inspiration.