Simple rate limiting for node.js streams, capable of capping both read and write streams.
npm install ratelimit
var ratelimit = require('ratelimit');
ratelimit(stream, bytesPerSecond);
var ratelimit = require('ratelimit');
var limited = ratelimit(stream, bytesPerSecond);
// ...
limited.end();
var ratelimit = require('ratelimit');
var limited = ratelimit(stream, bytesPerSecond);
limited.write('some data', 'utf8');
limited.write(new Buffer([1, 2, 3]));
var http = require('http')
, ratelimit = require('ratelimit');
http.get('http://someplace.com/path/file.zip', function(res) {
ratelimit(res, 65 * 1024);
res.on('data', function(data) {
// do whatever with data
});
});
See the tests for now.
- Test writable file streams.
- Examples (e.g. HTTP).