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.
Get the package from NPM:
npm install --save stream-chunkify
API and Example
The module exposes just one function:
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 =const fs =fs