# kompression

> koa compression middleware

Latest version **1.0.2** (published 2020-02-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install kompression
pnpm add kompression
yarn add kompression
bun add kompression
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-02-03 |
| First published | 2017-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/kompression) |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Tuan Anh Tran |
| Maintainers | tuananh |
| Keywords | koa, compression, middleware, brotli, gzip, inflate |

## Links

- npm: https://www.npmjs.com/package/kompression
- Repository: https://github.com/tuananh/kompression
- Issues: https://github.com/tuananh/kompression/issues
- npm.io page: https://npm.io/package/kompression

## Dependencies (5)

- [bytes](https://npm.io/package/bytes.md) ^3.1.0
- [iltorb](https://npm.io/package/iltorb.md) ^2.4.3
- [statuses](https://npm.io/package/statuses.md) ^1.5.0
- [koa-is-json](https://npm.io/package/koa-is-json.md) ^1.0.0
- [compressible](https://npm.io/package/compressible.md) ^2.0.17

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2020-02-03
- 1.0.0-rc2 (next) — 2017-11-18
- 1.0.1 — 2019-06-28
- 1.0.0 — 2017-11-18
- 1.0.0-rc1 — 2017-11-17

## README

# Kompression

[![npm](https://img.shields.io/npm/v/kompression.svg)](https://npm.im/kompression)
[![Build Status](https://dev.azure.com/me0499/kompresssion/_apis/build/status/tuananh.kompression?branchName=develop)](https://dev.azure.com/me0499/kompresssion/_build/latest?definitionId=2&branchName=develop)

This is a fork of [koa-compress](https://github.com/koajs/compress) with support for brotli compression.

Because `zlib` and `iltorb` options doesn't have much in common so including support for brotli
would be a breaking change.

I'm trimming down the available options in this package down to just `filter` and `threshold`.

## Example

```js
const compress = require('kompression')
const Koa = require('koa')

const app = new Koa()
app.use(
    compress({
        filter: function(content_type) {
            return /text/i.test(content_type)
        },
        threshold: 2048
    })
)
```

## Options

### filter

An optional function that checks the response content type to decide whether to compress.
By default, it uses [compressible](https://github.com/expressjs/compressible).

### threshold

Minimum response size in bytes to compress.
Default `1024` bytes or `1kb`.

## Manually turning compression on and off

You can always enable compression by setting `this.compress = true`.
You can always disable compression by setting `this.compress = false`.
This bypasses the filter check.

```js
app.use((ctx, next) => {
    ctx.compress = true
    ctx.body = fs.createReadStream(file)
})
```

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