Giter VIP home page Giter VIP logo

node-streamspeed's Introduction

streamspeed Build Status

A simple way to keep track of the speed of your readable streams.

Usage

var StreamSpeed = require('streamspeed');

var rs = fs.createReadStream('somefile.avi');
var ss = new StreamSpeed();
ss.add(rs);

// Listen for events emitted by streamspeed on the given stream.
ss.on('speed', function(speed, avgSpeed) {
  console.log('Reading at', speed, 'bytes per second');
});

Keep track of even a group of streams easily.

var group = new Streamspeed();
group.add(stream1);
group.add(stream2);
group.add(stream3);

group.on('speed', function(speed, avg) {
  console.log('now reading at', speed, 'bps');
});

example img

API

new StreamSpeed(timeUnit)

A group that can be used to watch several streams. Will emit speed events. timeUnit defaults to 1000 for speed per second.

StreamSpeed#add(stream)

Adds stream to group.

StreamSpeed#remove(stream)

Removes stream from group.

StreamSpeed#getStreams()

Returns a list of all streams in the group.

StreamSpeed.toHuman(bytes, timeUnit)

Convenient method to convert bytes to a human readable string.

StreamSpeed.toHuman(1500); // 1.46KB
StreamSpeed.toHuman(1024 * 1024) => 1MB
StreamSpeed.toHuman(1024 * 1024 * 20.5, 's') => 20.5MB/s

Event: 'speed'

  • Number - Speed at which streams in the group are being read.
  • Number - Average speed.

Will be emitted after the second time a stream is read and only if there is a change in speed.

Install

npm install streamspeed

Tests

Tests are written with mocha

npm test

License

MIT

node-streamspeed's People

Contributors

fent avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.