1. throttle
Node.js Transform stream that passes data through at `n` bytes per second
throttle
Package: throttle
Created by: TooTallNate
Last modified: Mon, 27 Jun 2022 06:23:35 GMT
Version: 1.0.3
Downloads: 22,014
Repository: https://github.com/TooTallNate/node-throttle

Install

npm install throttle
yarn add throttle

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

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code