Socket
Socket
Sign inDemoInstall

stream-throttle

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-throttle

A rate limiter for Node.js streams.


Version published
Weekly downloads
548K
decreased by-20.2%
Maintainers
1
Weekly downloads
 
Created

What is stream-throttle?

The stream-throttle npm package is used to throttle the rate of data flowing through a stream. This can be useful in various scenarios such as limiting the bandwidth usage, controlling the rate of data processing, or simulating network conditions.

What are stream-throttle's main functionalities?

Throttle Read Stream

This feature allows you to throttle the read stream to a specified rate. In this example, the data from 'input.txt' is read at a rate of 1 KB per second and written to 'output.txt'.

const fs = require('fs');
const { Throttle } = require('stream-throttle');

const readStream = fs.createReadStream('input.txt');
const throttle = new Throttle({ rate: 1024 }); // 1 KB per second
const writeStream = fs.createWriteStream('output.txt');

readStream.pipe(throttle).pipe(writeStream);

Throttle Write Stream

This feature allows you to throttle the write stream to a specified rate. In this example, the data from 'input.txt' is read and written to 'output.txt' at a rate of 2 KB per second.

const fs = require('fs');
const { Throttle } = require('stream-throttle');

const readStream = fs.createReadStream('input.txt');
const throttle = new Throttle({ rate: 2048 }); // 2 KB per second
const writeStream = fs.createWriteStream('output.txt');

readStream.pipe(writeStream).pipe(throttle);

Throttle Duplex Stream

This feature allows you to throttle a duplex stream, which is both readable and writable. In this example, the duplex stream is throttled to a rate of 512 bytes per second.

const { Throttle } = require('stream-throttle');
const { Duplex } = require('stream');

const duplexStream = new Duplex({
  read(size) {
    this.push('data');
  },
  write(chunk, encoding, callback) {
    console.log(chunk.toString());
    callback();
  }
});

const throttle = new Throttle({ rate: 512 }); // 512 bytes per second

duplexStream.pipe(throttle).pipe(duplexStream);

Other packages similar to stream-throttle

Keywords

FAQs

Package last updated on 08 Apr 2014

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc