Chop a data stream into fixed size buffer chunks. Written in ES2015.
$ npm install chop-stream
const ChopStream = require('chop-stream')
const chop = new ChopStream({ size: 8, padding: true })
chop.on('data', (chunk) => console.log(chunk))
process.stdin.pipe(chop)
$ echo abcdefghijklmnopqrstuvwxyz | node example.js
<Buffer 61 62 63 64 65 66 67 68>
<Buffer 69 6a 6b 6c 6d 6e 6f 70>
<Buffer 71 72 73 74 75 76 77 78>
<Buffer 79 7a 0a 00 00 00 00 00>
See the examples folder for more details on how to customize the animation.
ChopStream is a node Transform stream.
size
: size of output chunks. Can be omitted and set in options instead.
padding
: pad the end of a stream with zeroes to align the last chunk.
Has this not been done before?
Sure, here are a few examples:
- stream-chunker
- stream-chunkify
- chunk-stream
- chopped-stream
- choppa
- block-stream2
- block-stream
- batched-stream
- bytechunker
- pull-block
A few? Did we really need yet another module?
Probably not, but I wanted a small dependency-free ES2015 version.
Why open a pull request, when you can follow the trend and add yet another module.