transform-clump

1.0.5 • Public • Published

transform-clump

Build Status Coverage Status NPM version

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

$ npm install transform-clump --save

Example

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

$ make test

To generate a coverage report:

$ make test-cov

Credits

  • urlgrey for the Makefile inspiration.

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i transform-clump

    Weekly Downloads

    0

    Version

    1.0.5

    License

    MIT

    Last publish

    Collaborators

    • tanem