chop-stream

Chop a data stream into fixed size buffer chunks

Usage no npm install needed!

<script type="module">
  import chopStream from 'https://cdn.skypack.dev/chop-stream';
</script>

README

chop-stream

npm downloads dependencies license

Chop a data stream into fixed size buffer chunks. Written in ES2015.

install

$ npm install chop-stream

example

const ChopStream = require('chop-stream')

const chop = new ChopStream({ size: 8, padding: true })

chop.on('data', (chunk) => console.log(chunk))

process.stdin.pipe(chop)

output

<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.

usage

ChopStream is a node Transform stream.

chop = new ChopStream(size, options = { padding: false, size: 1024 })

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.

see also

Has this not been done before?

Sure, here are a few examples:

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.