Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tuananh/kompression
This is a fork of koa-compress with support for brotli compression
https://github.com/tuananh/kompression
brotli compression gzip koa middleware
Last synced: 29 days ago
JSON representation
This is a fork of koa-compress with support for brotli compression
- Host: GitHub
- URL: https://github.com/tuananh/kompression
- Owner: tuananh
- License: mit
- Archived: true
- Created: 2017-11-17T17:47:18.000Z (about 7 years ago)
- Default Branch: develop
- Last Pushed: 2020-07-16T04:34:48.000Z (over 4 years ago)
- Last Synced: 2024-11-12T23:35:44.712Z (about 1 month ago)
- Topics: brotli, compression, gzip, koa, middleware
- Language: JavaScript
- Homepage:
- Size: 250 KB
- Stars: 8
- Watchers: 4
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - kompression - compress with support for brotli compression | tuananh | 8 | (JavaScript)
- awesome-koa - kompression - koa-compress的fork版本,用于支持brotli压缩 ![](https://img.shields.io/github/stars/tuananh/kompression.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/kompression.svg?style=flat-square) (仓库 / 中间件)
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)
})
```