Skip to content

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.

License

Notifications You must be signed in to change notification settings

ItalyPaleAle/node-stream-chunkify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'))

About

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.

Resources

License

Stars

Watchers

Forks

Packages