# koa-byte-length

> get the byte length of a response

Latest version **1.0.2** (published 2014-05-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-byte-length
pnpm add koa-byte-length
yarn add koa-byte-length
bun add koa-byte-length
```

## 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 | 1.0.2 |
| Published | 2014-05-20 |
| First published | 2014-05-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jonathan Ong |
| Maintainers | jongleberry |

## Links

- npm: https://www.npmjs.com/package/koa-byte-length
- Repository: https://github.com/koajs/byte-length
- Issues: https://github.com/koajs/byte-length/issues
- npm.io page: https://npm.io/package/koa-byte-length

## Dependencies (1)

- [passthrough-counter](https://npm.io/package/passthrough-counter.md) 0

## Recent versions

- 1.0.2 (latest) — 2014-05-20
- 1.0.1 — 2014-05-20

## README

# Byte Length

Get the response length of a Koa response body,
streams in particular.

```js
app.use(function* (next) {
  yield* next
  console.log(this.response.byteLength)
})

app.use(require('byte-length')())
```

`byteLength` is added to `this.response`.
If a non-stream body is set,
this is the `content-length`.
If a stream body is set,
this is the current amount of bytes sent to the response.

To find the total amount of bytes sent,
check the `byteLength` property after the response emits the `finish` event:

```js
app.use(function* (next) {
  var ctx = this

  this.res.once('finish', function () {
    console.log('bytes sent: ' + ctx.response.byteLength)
  })

  yield* next
})

app.use(require('byte-length')())
```

You may also use it as a function,
though it's still a generator even though it's not async.

```js
var byteLength = require('byte-length')()

app.use(function* (next) {
  yield* byteLength.call(this)
  yield* next

  // later
  var response = this.response
  this.res.once('finish', function () {
    console.log(response.byteLength)
  })
})
```

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