A simple way to keep track of the speed of your readable streams.
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');
});
A group that can be used to watch several streams. Will emit speed
events. timeUnit
defaults to 1000
for speed per second.
Adds stream to group.
Removes stream from group.
Returns a list of all streams in the group.
Curent speed.
Current average speed.
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
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.
npm install streamspeed
Tests are written with mocha
npm test
MIT