How to use the stream-throttle.Throttle function in stream-throttle

To help you get started, we’ve selected a few stream-throttle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eight04 / image-picka / test / server.js View on Github external
handle(req, res) {
			const image = fs.createReadStream(__dirname + "/test.png");
			image.pipe(new Throttle({rate: 100})).pipe(res);
		}
	}
github jakearchibald / range-request-test / index.js View on Github external
function getFileStream(opts = {}) {
  return fs.createReadStream(`${__dirname}/static/test.wav`, opts)
    .pipe(new Throttle({ rate: opts.rate }));
}
github jakearchibald / range-request-test / index.js View on Github external
let toSend = content;

      if (contentOffset) {
        toSend = toSend.slice(contentOffset % toSend.length);
        contentOffset = 0;
      }

      if (toSend.length > bytesToSend) {
        toSend = toSend.slice(0, bytesToSend);
      }

      bytesToSend -= toSend.length;

      this.push(toSend);
    }
  }).pipe(new Throttle({ rate })).pipe(res);
});
github 131 / h264-live-player / server.js View on Github external
wss.on('connection', function(socket){


  console.log('New guy');

  var readStream = fs.createReadStream(source);

    //throttle for real time simulation
  readStream = readStream.pipe(new Throttle({rate: sourceThrottleRate}));

    var separator = new Buffer([0,0,0,1]);//NAL break
  readStream = readStream.pipe(new Splitter(separator));

  readStream.pause();


  socket.send(JSON.stringify({action : "init", width: width, height : height}));

  socket.on("message", function(data){
    var cmd = "" + data, action = data.split(' ')[0];
    if(action == "REQUESTSTREAM")
      readStream.resume();
    if(action == "STOPSTREAM")
      readStream.pause();
    console.log("Incomming data", data);
github qiniu / kodo-browser / node / s3store / lib / ioutil.js View on Github external
function tryGettingObject(cb) {
    if (isAborted) return;

    const fileStream = fs.createWriteStream(localFile, {
      flags: 'w+',
      autoClose: true
    });

    const params = {
      Bucket: s3params.Bucket,
      Key: s3params.Key,
    };

    s3downloader = self.s3.getObject(params).createReadStream();
    if (self.downloadSpeedLimit) {
      s3downloader = s3downloader.pipe(new Throttle({rate: self.downloadSpeedLimit * 1024}));
    }
    s3downloader.on('data', (chunk) => {
      if (isAborted) return;

      downloader.progressLoaded += chunk.length;
      downloader.emit('progress', downloader);
    });
    s3downloader.on('end', () => {
      if (isAborted) return;

      if (downloader.progressTotal != downloader.progressLoaded) {
        cb(new Error(`ContentLength mismatch, got ${downloader.progressLoaded}, expected ${downloader.progressTotal}`));
        return;
      }

      downloader.emit('progress', downloader);
github ghaiklor / terminal-canvas / examples / video.js View on Github external
function playVideo(info) {
  const video = info.formats.filter(format => format.resolution === '144p' && format.audioBitrate === null).sort((a, b) => a.container === 'webm' ? -1 : 1)[0];
  const m = video.size.match(/^(\d+)x(\d+)$/);
  const videoSize = { width: m[1], height: m[2] };
  const frameHeight = Math.round(canvas._height * 2);
  const frameWidth = Math.round(frameHeight * (videoSize.width / videoSize.height));
  const frameSize = frameWidth * frameHeight * 3;

  ffmpeg.rawImageStream(video.url, { fps: 30, width: frameWidth })
    .on('start', () => canvas.saveScreen().reset())
    .on('end', () => canvas.restoreScreen())
    .pipe(new Throttle({ rate: frameSize * 30 }))
    .pipe(new RawImageStream(frameSize))
    .on('data', function (frameData) {
      const ascii = imageToAscii(frameData, frameWidth, frameHeight);

      for (let y = 0; y < frameHeight; y++) {
        for (let x = 0; x < frameWidth; x++) {
          canvas
            .moveTo(x + (canvas._width / 2 - frameWidth / 2), y)
            .write(ascii[y * frameWidth + x] || '');
        }
      }

      canvas.flush();
    });
}
github GavinDmello / heinrich / lib / network.js View on Github external
function throttleStream(stream, rate) {
    stream.pipe(new Throttle({ rate: rate }))
    return stream
}
github sematext / logagent-js / lib / plugins / input / tcp.js View on Github external
function Throttle (maxRate) {
  var inputRate = maxRate || 1024 * 1024 * 100
  var chunkSize = inputRate / 10
  if (chunkSize < 1) {
    chunkSize = 1
  }
  return new StreamThrottle({
    chunksize: chunkSize,
    rate: inputRate || 1024 * 1024 * 100
  })
}

stream-throttle

A rate limiter for Node.js streams.

BSD-3-Clause
Latest version published 10 years ago

Package Health Score

65 / 100
Full package analysis