Installations
npm install koa-compress
Developer
koajs
Developer Guide
Module System
CommonJS
Min. Node Version
>= 12
Typescript Support
No
Node Version
16.19.0
NPM Version
8.19.3
Statistics
437 Stars
180 Commits
36 Forks
10 Watching
7 Branches
28 Contributors
Updated on 18 Nov 2024
Bundle Size
162.70 kB
Minified
26.36 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
79,205,506
Last day
-16.4%
60,780
Compared to previous day
Last week
-2.2%
356,049
Compared to previous week
Last month
10.4%
1,537,715
Compared to previous month
Last year
-17.6%
16,208,721
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Koa Compress
Compress middleware for Koa
Example
1const compress = require('koa-compress') 2const Koa = require('koa') 3 4const app = new Koa() 5app.use(compress({ 6 filter (content_type) { 7 return /text/i.test(content_type) 8 }, 9 threshold: 2048, 10 gzip: { 11 flush: require('zlib').constants.Z_SYNC_FLUSH 12 }, 13 deflate: { 14 flush: require('zlib').constants.Z_SYNC_FLUSH, 15 }, 16 br: false // disable brotli 17}))
Maintainers
- Lead: @jonathanong @jongleberry
- Team: @koajs/compress
Options
filter<Function>
1function (mimeType: string): Boolean { 2 3}
An optional function that checks the response content type to decide whether to compress. By default, it uses compressible.
options.threshold<String|Number>
Minimum response size in bytes to compress.
Default 1024
bytes or 1kb
.
options[encoding]<Object>
The current encodings are, in order of preference: br
, gzip
, deflate
.
Setting options[encoding] = {}
will pass those options to the encoding function.
Setting options[encoding] = false
will disable that encoding.
options.br
Brotli compression is supported in node v11.7.0+, which includes it natively. As of v5.1.0, the default quality level is 4 for performance reasons.
options.defaultEncoding<String>
An optional string, which specifies what encoders to use for requests without
Accept-Encoding.
Default identity
.
The standard dictates to treat such requests as *
meaning that all compressions are permissible,
yet it causes very practical problems when debugging servers with manual tools like curl
, wget
, and so on.
If you want to enable the standard behavior, just set defaultEncoding
to *
.
Manually turning compression on and off
You can always enable compression by setting ctx.compress = true
.
You can always disable compression by setting ctx.compress = false
.
This bypasses the filter check.
1app.use((ctx, next) => { 2 ctx.compress = true 3 ctx.body = fs.createReadStream(file) 4})
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/koajs/.github/SECURITY.md:1
- Info: Found linked content: github.com/koajs/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/koajs/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/koajs/.github/SECURITY.md:1
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/koajs/compress/node.js.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/koajs/compress/node.js.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
Found 1/5 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node.js.yml:1
- Info: no jobLevel write permissions found
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 27 are checked with a SAST tool
Reason
10 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-h452-7996-h45h
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
3.9
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More