1.0.5 • Published 10 years ago

transform-clump v1.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

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.
1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago