Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@kldzj/stream-throttle
Advanced tools
A simple Node.js stream throttler.
Using yarn:
$ yarn add @kldzj/stream-throttle
Using npm:
$ npm i -S @kldzj/stream-throttle
rate
: The rate in bytes per second at which to emit data.burst
: The burst rate in bytes per second. Must be greather than or equal to rate
. Defaults to rate
.chunkSize
: The size of chunks to split the received data into. Must be less than or equal to rate
. Defaults to rate / 10
.Throttle
Used to throttle the output rate of a single stream.
import { Throttle } from '@kldzj/stream-throttle';
const throttle = new Throttle({ rate: 10 });
process.stdin.pipe(throttle).pipe(process.stdout);
ThrottleGroup
Used to throttle the output rate across multiple streams.
import { createConnection } from 'net';
import { ThrottleGroup } from '@kldzj/stream-throttle';
const group = new ThrottleGroup({ rate: 1024 * 1024 });
const addr = { host: 'www.google.com', port: 80 };
const throttled1 = createConnection(addr).pipe(group.createThrottle());
const throttled2 = createConnection(addr).pipe(group.createThrottle());
// ...
const group = new ThrottleGroup({ rate: 1024 * 1024 });
// or group = new Throttle({ rate: 1024 * 1024 }).group;
// ...
group.setRate(4 * 1024 * 1024);
// in case you calculate the chunkSize differently
// you should call `setChunkSize` as well, as `setRate`
// recalculates `chunkSize`
group.setChunkSize(group.rate / 6);
// in addition, you can also call `setBurst` if
// you want to change the burst rate
group.setBurst(group.rate * 1.5);
// ...
stream-throttle
).FAQs
Throttle one or multiple stream(s) to a maximum rate
We found that @kldzj/stream-throttle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.