# transfer-rate

> calculate transfer-rate of request/response

Latest version **2.2.0** (published 2017-12-31) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install transfer-rate
pnpm add transfer-rate
yarn add transfer-rate
bun add transfer-rate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2017-12-31 |
| First published | 2014-08-13 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | hex7c0 |
| Maintainers | hex7c0 |
| Keywords | transfer, rate, bandwidth |

## Links

- npm: https://www.npmjs.com/package/transfer-rate
- Repository: https://github.com/hex7c0/transfer-rate
- Issues: https://github.com/hex7c0/transfer-rate/issues
- npm.io page: https://npm.io/package/transfer-rate

## Dependencies (1)

- [on-finished](https://npm.io/package/on-finished.md) 2.3.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2017-12-31
- 2.1.0 — 2017-05-14
- 2.0.1 — 2017-01-10
- 2.0.0 — 2017-01-09
- 1.2.0 — 2016-09-12
- 1.1.3 — 2015-11-25
- 1.1.2 — 2015-09-25
- 1.1.1 — 2015-08-17
- 1.1.0 — 2015-04-04
- 1.0.6 — 2015-02-05
- 1.0.5 — 2015-01-01
- 1.0.4 — 2014-11-09
- 1.0.3 — 2014-10-27
- 1.0.2 — 2014-10-04
- 1.0.1 — 2014-09-01
- … 2 more at https://npm.io/package/transfer-rate/versions

## README

# [transfer-rate](https://github.com/hex7c0/transfer-rate)

[![NPM version](https://img.shields.io/npm/v/transfer-rate.svg)](https://www.npmjs.com/package/transfer-rate)
[![Linux Status](https://img.shields.io/travis/hex7c0/transfer-rate.svg?label=linux-osx)](https://travis-ci.org/hex7c0/transfer-rate)
[![Windows Status](https://img.shields.io/appveyor/ci/hex7c0/transfer-rate.svg?label=windows)](https://ci.appveyor.com/project/hex7c0/transfer-rate)
[![Dependency Status](https://img.shields.io/david/hex7c0/transfer-rate.svg)](https://david-dm.org/hex7c0/transfer-rate)
[![Coveralls](https://img.shields.io/coveralls/hex7c0/transfer-rate.svg)](https://coveralls.io/r/hex7c0/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

```bash
npm install transfer-rate
```
or
```bash
git clone git://github.com/hex7c0/transfer-rate.git
```

## API

inside expressjs project
```js
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.
```js
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](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](https://github.com/jshttp/on-finished) module

### [License Apache2](LICENSE)

---
_Source: https://npm.io/package/transfer-rate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
