Skip to content
throttle a stream with backpressure
JavaScript
Find file
Latest commit 8c28a67 Jun 4, 2014 @substack merged
Failed to load latest commit information.
bin
example
test
.travis.yml
LICENSE
index.js
package.json
readme.markdown example Jun 4, 2014

readme.markdown

brake

throttle a stream with backpressure

build status

example

Take a bulk readable stream stream and throttle it down to 10 bytes per second:

var Readable = require('readable-stream').Readable;
var brake = require('brake');

var bulk = new Readable;
bulk._read = function () {};

bulk.push(Array(1001).join('A'));
bulk.push(null);

bulk.pipe(brake(10)).pipe(process.stdout);

There's also a brake command as part of this package:

$ brake 30 readme.markdown | pv > /dev/null
1.53kB 0:00:51 [30.3B/s] [                                       <=>   ]

methods

var brake = require('brake')

var b = brake(rate, opts)

Return a transform stream b that applies backpressure when more data than the rate allows is written.

  • opts.rate - how many bytes to emit for each interval of length period

  • opts.period - How often to check the output length in milliseconds. Default value: 1000.

If opts is a number, its value will be used for the opts.period.

usage

usage:

    brake OPTIONS [rate] {file | -}
    brake OPTIONS [rate] [period] {file | -}
    brake OPTIONS {file | -}

OPTIONS:

  -r, --rate     How many bytes to emit for each interval of length `period`

  -p, --period   How often to check the output length in milliseconds.
                 default value: 1000

install

To get the library, with npm do:

npm install brake

To get the command, with npm do:

npm install -g brake

license

MIT

Something went wrong with that request. Please try again.