Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

throttle

TooTallNate18.5k1.0.3TypeScript support: definitely-typed

Node.js Transform stream that passes data through at n bytes per second

readme

node-throttle

Node.js Transform stream that passes data through at n bytes per second

Build Status

This module offers a Throttle passthrough stream class, which allows you to write data to it and it will be passed through in n bytes per second. It can be useful for throttling HTTP uploads or to simulate reading from a file in real-time, etc.

Installation

$ npm install throttle

Example

Here's an example of throttling stdin at 1 byte per second and outputting the data to stdout:

var Throttle = require('throttle');

// create a "Throttle" instance that reads at 1 bps
var throttle = new Throttle(1);

process.stdin.pipe(throttle).pipe(process.stdout);

We can see it in action with the echo command:

API

Throttle()

The Throttle passthrough stream class is very similar to the node core stream.Passthrough stream, except that you specify a bps "bytes per second" option and data will not be passed through faster than the byte value you specify.

You can invoke with just a bps Number and get the rest of the default options. This should be more common:

process.stdin.pipe(new Throttle(100 * 1024)).pipe(process.stdout);

Or you can pass an options Object in, with a bps value specified along with other options:

var t = new Throttle({ bps: 100 * 1024, chunkSize: 100, highWaterMark: 500 });

changelog

1.0.3 / 2013-03-07

  • test: update test Readable stream classes for node v0.9.11 API changes

1.0.2 / 2013-02-26

  • package: depend on "readable-stream" >= v0.3.0
  • travis: don't test node v0.7.x

1.0.1 / 2013-02-10

  • Fix bug with slow Readable streams

1.0.0 / 2013-02-08

  • Refactor API for streams2
  • Throttle instances are now distinct streams, original Readable is not changed

0.0.1 / 2011-01-24

  • Initial release