stream-chunker
A transform stream which chunks incoming data into chunkSize
byte chunks.
api
var chunker = require('stream-chunker')(chunkSize, [flush])
Returns a new chunker. Chunker is a duplex (tansform) stream. You can write data into the
chunker, and regardless of the incoming data, the readable side will emit data
in chunkSize
byte chunks.
chunkSize
: integer
- Size in bytes of the desired chunksflush
: boolean
- Optional. Flush inclomplete chunk data on stream end. Default is false
.
An example
var Lorem = require('loremipstream');
var sampleStream = new Lorem({
size: 1000,
dataSize: 10,
dataInteval: 100
});
var CHUNK_SIZE = 4;
Chunker = require('stream-chunker');
var chunker = Chunker(CHUNK_SIZE)
chunker.on('data', function(data) {
console.log('Handle '+CHUNK_SIZE+'bytes at a time: ' + data.toString('utf8'));
});
sampleStream.pipe(chunker);
License
MIT