stream-chunkify
v1.0.0
Published
Transforms a stream so all chunks have the same size in bytes, regardless of the input stream. The last chunk may be smaller if there's remaining data.
Downloads
27
Readme
stream-chunkify
This Node.js module is a small (~50 SLOC) that implements a stream transform function to chunk a readable stream into another stream with a fixed byte size.
The input stream can come in chunks that are either bigger or smaller than the desired chunk size, and this transform function will take care of all cases. Please note that the last chunk might be smaller than the desired chunk size if the input stream doesn't evenly divide into chunks of the required size.
This module is based on through2.
Install
Get the package from NPM:
npm install --save stream-chunkify
API and Example
The module exposes just one function:
StreamChunkify(chunkSize)
chunkSize
is the desired size of the chunks, in bytes.
The return value is a function that can be used with pipe()
, for example:
const StreamChunkify = require('StreamChunkify')
const fs = require('fs')
fs.createReadStream('input.txt')
.pipe(StreamChunkify(100))
.pipe(fs.createWriteStream('output.txt'))