1 | # Koa Compress [![Build Status](https://travis-ci.org/jonathanong/koa-compress.png)](https://travis-ci.org/jonathanong/koa-compress)
|
2 |
|
3 | Compress middleware for Koa
|
4 |
|
5 | ## Example
|
6 |
|
7 | ```js
|
8 | var compress = require('koa-compress')
|
9 | var koa = require('koa')
|
10 |
|
11 | var app = koa()
|
12 | app.use(compress({
|
13 | filter: /text/i,
|
14 | threshold: 2048,
|
15 | flush: require('zlib').Z_SYNC_FLUSH
|
16 | }))
|
17 | ```
|
18 |
|
19 | ## Options
|
20 |
|
21 | The options are passed to `zlib`: http://nodejs.org/api/zlib.html#zlib_options
|
22 |
|
23 | ### filter
|
24 |
|
25 | Regular expression filter to check the response content type to decide whether to compress.
|
26 | By default, `/json|text|javascript|dart/i`.
|
27 |
|
28 | ### threshold
|
29 |
|
30 | Minimum response size in bytes to compress.
|
31 | Default `1024` bytes or `1kb`.
|
32 |
|
33 | ## Manually turning compression on and off
|
34 |
|
35 | You can always enable compression by setting `this.compress = true`.
|
36 | You can always disable compression by setting `this.compress = false`.
|
37 | This bypasses the filter check.
|
38 |
|
39 | ```js
|
40 | app.use(function (next) {
|
41 | return function *() {
|
42 | this.compress = true
|
43 | this.body = fs.createReadStream(file)
|
44 | }
|
45 | })
|
46 | ```
|
47 |
|
48 | ## License
|
49 |
|
50 | The MIT License (MIT)
|
51 |
|
52 | Copyright (c) 2013 Jonathan Ong me@jongleberry.com
|
53 |
|
54 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
55 | of this software and associated documentation files (the "Software"), to deal
|
56 | in the Software without restriction, including without limitation the rights
|
57 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
58 | copies of the Software, and to permit persons to whom the Software is
|
59 | furnished to do so, subject to the following conditions:
|
60 |
|
61 | The above copyright notice and this permission notice shall be included in
|
62 | all copies or substantial portions of the Software.
|
63 |
|
64 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
65 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
66 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
67 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
68 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
69 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
70 | THE SOFTWARE. |
\ | No newline at end of file |