transfer-rate
v2.2.0
Published
calculate transfer-rate of request/response
Downloads
5,202
Readme
transfer-rate
Calculate transfer-rate of request/response with different option for customization. Build a function that, calculate ratio between data and time.
Installation
Install through NPM
npm install transfer-rate
or
git clone git://github.com/hex7c0/transfer-rate.git
API
inside expressjs project
var transfer = require('transfer-rate');
var app = require('express')();
var rate = transfer();
app.get('/', function(req, res) {
var start = process.hrtime();
res.send('ok');
console.log(transfer(req, res, start));
});
Methods
Calculation is store inside res
and req
Object and returned from function.
req.transferRate
transfer(options) // builder
options
data
String Accepted string are related to http://en.wikipedia.org/wiki/Data_rate_units[Byte, KB, MB, bit, Kb, Mb]
(default "KB")time
- String Accepted string for calculate ratio are[nanosecond, millisecond, second]
(default "second")response
- Boolean Flag for calculate transfer rate of response(true) or request(false) (default "response")output
- Boolean Flag for display(true) extra information likeKB/s
or only data(false) as string (default "display")
rate(req, res, start) // calculator
req
req
- Object Client request object (default "required")
res
res
- Object Client response object (default "required")
start
start
- Array High precision time, fromprocess.hrtime()
(default "required")
Examples
Take a look at my examples
For chunked data, wait for a fix with event emitter https://github.com/hex7c0/transfer-rate/tree/master/examples/chunk_res.js or use on-finished module