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. This modules has no notion of objectMode
, everything
written to this stream must be a string
or a buffer
.
chunkSize
: integer
- Size in bytes of the desired chunks.flush
: boolean
- Optional. Flush incomplete chunk data on stream end. Default is false
.
Simple example
var fs = require('fs');
var chunker = require('stream-chunker');
fs.createReadStream('/someFile')
.pipe(chunks(16))
.pipe(somethingThatExpects16ByteChunks());
Full working example example
var Lorem = require('loremipstream');
var sampleStream = new Lorem({
size: 100,
dataSize: 10,
dataInteval: 100
});
var Chunker = require('stream-chunker');
var chunker = Chunker(16, true);
chunker.on('data', function(data) {
console.log('Chunk: ' + data.toString('utf8'));
});
sampleStream.pipe(chunker);
License
MIT