chop-stream

0.0.2 • Public • Published

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.

Package Sidebar

Install

npm i chop-stream

Weekly Downloads

4

Version

0.0.2

License

MIT

Unpacked Size

4.7 kB

Total Files

5

Last publish

Collaborators

  • mathiasvr