Have ideas to improve npm?Join in the discussion! ¬Ľ

    transfer-rate

    2.2.0¬†‚Äʬ†Public¬†‚Äʬ†Published

    transfer-rate

    NPM version Linux Status Windows Status Dependency Status Coveralls

    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 like KB/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, from process.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

    License Apache2

    Install

    npm i transfer-rate

    DownloadsWeekly Downloads

    2,543

    Version

    2.2.0

    License

    Apache-2.0

    Last publish

    Collaborators

    • avatar