npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stream-bouncer

v1.0.2

Published

a stream queue module

Downloads

14

Readme

stream-bouncer

NPM version

alt-text

Create a queue of streams and have the bouncer make sure they stay in line!

Example

var fs = require('fs');
var StreamBouncer = require('stream-bouncer');

var bouncer = new StreamBouncer({
  streamsPerTick: 1,
  poll: 1000
});

bouncer.on('error', function(err) {
  console.error(err);
});

var counter = 1;

bouncer.on('close', function(str) {
  console.log('stream finished', str.path);
});

bouncer.on('count', function(count) {
  console.log([count, 'streams remaining'].join(' '));
});

for (var i = 0; i < 10; i++) {
  bouncer.push({
    source: fs.createReadStream(['/Users/gabrieltesta/Downloads/sync/', i, '.mp3'].join('')),
    middle: i % 2 == 0 ? zlib.createGzip() : undefined,
    destination: fs.createWriteStream(['/Users/gabrieltesta/Downloads/slave/', i*counter, '.mp3'].join('')),
  });
}

Details

A stream module that allows you to enqueue a bunch of streams without worrying about defering the piping. Just queue up as many streams as you want and let the module take care of the piping for you!

Methods

var StreamBouncer = require('stream-bouncer');

var bouncer = new StreamBouncer();

Create a new instance of a bouncer.

Use it

bouncer.push({
  source: readStream,
  middle: someStream, //middle isn't required
  destination: writeStream
});

#Events

bouncer.on('start', function(str){...});

Fires when one of the streams in the queue starts, passes a stream to the callback. str is the stream.source object.

bouncer.on('close', function(str){...});

fires when one of the streams in the queue finishes, passes a stream to the callback. str is the stream.source object.

bouncer.on('count', function(count){...});

fires when the number of streams in the queue changes, passes a number to the callback.

bouncer.on('error', function(err){...});

forwards an error object to the cb.

Options

var defaultOptions  = {
  streamsPerTick: 5, //how many simultaneous streams to process per tick
  poll: 250, //how long to wait before process {count} # of streams in ms
  throttle: false, // throttle the streams speed.
  speed: null //only required if throttling is active
}

###example of overloading options

var bouncer = new StreamBouncer({
  streamsPerTick: 1,
  poll: 1000,
  throttle: true,
  speed: 2 * 1024 * 1024 //max 2 MB/s tranfer
});

Install

With npm do:

npm install stream-bouncer

to get the library.

License

MIT