brake
throttle a stream with backpressure
Last updated 6 years ago by substack .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install brake 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.0.1                                ...           latest (6 years ago)

5 Versions

  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           8 years ago
  • 0.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (3)
Dev Dependencies (1)

Copyright 2014 - 2017 © taobao.org |