meterstream

1.0.1 • Public • Published

meterstream

Build Status

Transform stream that emits a MeterStream.OverflowError error if it has read more than maxBytes bytes.

Note: if more than maxBytes is read, the transform will ensure that exactly maxBytes have been flushed to the readable side before emitting the OverflowError.

Install

npm install --save meterstream

Requires Node v6+

Usage

new MeterStream(maxBytes = Infinity)

Returns a pass through stream where maxBytes (defaults to Infinity) is the max number of bytes to pass through before emitting an error.

See ./test directory for usage examples.

import MeterStream from 'meterstream'

process.stdin
  .pipe(new MeterStream(5))
  .on('error', (err) => {
    console.error('Read more than 5 bytes from stdin')
    console.error(err)
    process.exit(1)
  })
  .pipe(process.stdout)


// echo -n "123456789" | babel-node src/demo.js
// 12345Read more than 5 bytes from stdin
// Error: Stream exceeded specified max of 5 bytes.
//     at OverflowError (...)
//     at ....

/meterstream/

    Package Sidebar

    Install

    npm i meterstream

    Weekly Downloads

    56

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • olalonde