Socket
Socket
Sign inDemoInstall

ratelimit

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ratelimit

simple stream rate limiting for node.js


Version published
Weekly downloads
1.5K
increased by12.15%
Maintainers
1
Install size
13.5 kB
Created
Weekly downloads
 

Readme

Source

ratelimit

Simple rate limiting for node.js streams, capable of capping both read and write streams.

Install

npm install ratelimit

Usage

Basic

var ratelimit = require('ratelimit');
ratelimit(stream, bytesPerSecond);

To clear the limit

var ratelimit = require('ratelimit');
var limited = ratelimit(stream, bytesPerSecond);
// ...
limited.end();

Write limit

var ratelimit = require('ratelimit');
var limited = ratelimit(stream, bytesPerSecond);
limited.write('some data', 'utf8');
limited.write(new Buffer([1, 2, 3]));

HTTP (see examples/http for a more elaborate example)

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
  });
});

Other examples

See the tests for now.

Todo

  • Test writable file streams.
  • Examples (e.g. HTTP).

FAQs

Last updated on 03 Oct 2012

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc