{"id":13779189,"url":"https://github.com/koajs/compress","last_synced_at":"2026-02-13T00:23:33.793Z","repository":{"id":10158127,"uuid":"12238295","full_name":"koajs/compress","owner":"koajs","description":"Compress middleware for koa","archived":false,"fork":false,"pushed_at":"2026-01-06T09:30:22.000Z","size":512,"stargazers_count":445,"open_issues_count":7,"forks_count":37,"subscribers_count":8,"default_branch":"master","last_synced_at":"2026-02-06T15:36:49.261Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koajs.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2013-08-20T08:29:58.000Z","updated_at":"2025-12-21T12:42:03.000Z","dependencies_parsed_at":"2025-04-13T22:18:26.307Z","dependency_job_id":"c61ff0b6-d160-49d0-89d7-fa50f45ea985","html_url":"https://github.com/koajs/compress","commit_stats":{"total_commits":175,"total_committers":23,"mean_commits":7.608695652173913,"dds":0.6457142857142857,"last_synced_commit":"0852175dfdb61cef1681d0d138ae72fd18208183"},"previous_names":["jonathanong/koa-compress"],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/koajs/compress","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fcompress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fcompress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fcompress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fcompress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/compress/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fcompress/sbom","scorecard":{"id":532255,"data":{"date":"2025-08-11","repo":{"name":"github.com/koajs/compress","commit":"0deefb8a19db5e6bdd593332c6c6905579d13965"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5.3,"checks":[{"name":"Code-Review","score":3,"reason":"Found 2/6 approved changesets -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"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"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":2,"reason":"1 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":4,"reason":"dependency not pinned by hash detected -- score normalized to 4","details":["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","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/koajs/compress/node.js.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/node.js.yml:30: 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:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   1 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":10,"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"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"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"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T05:59:12.882Z","repository_id":10158127,"created_at":"2025-08-20T05:59:12.882Z","updated_at":"2025-08-20T05:59:12.882Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29336024,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T14:34:07.188Z","status":"ssl_error","status_checked_at":"2026-02-11T14:34:06.809Z","response_time":97,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:01:02.309Z","updated_at":"2026-02-13T00:23:33.781Z","avatar_url":"https://github.com/koajs.png","language":"JavaScript","readme":"# Koa Compress\n\n[![Node.js CI](https://github.com/koajs/compress/workflows/Node.js%20CI/badge.svg?branch=master)](https://github.com/koajs/compress/actions?query=workflow%3A%22Node.js+CI%22+branch%3Amaster)\n[![codecov](https://codecov.io/gh/koajs/compress/branch/master/graph/badge.svg)](https://codecov.io/gh/koajs/compress)\n\nCompress middleware for Koa\n\n## Example\n\n```js\nconst compress = require(\"koa-compress\");\nconst Koa = require(\"koa\");\n\nconst app = new Koa();\napp.use(\n  compress({\n    filter(content_type) {\n      return /text/i.test(content_type);\n    },\n    threshold: 2048,\n    gzip: {\n      flush: require(\"zlib\").constants.Z_SYNC_FLUSH,\n    },\n    deflate: {\n      flush: require(\"zlib\").constants.Z_SYNC_FLUSH,\n    },\n    zstd: {\n      flush: require(\"zlib\").constants.Z_SYNC_FLUSH,\n    },\n    br: false, // disable brotli\n  }),\n);\n```\n\n## Maintainers\n\n- Lead: @jonathanong [@jongleberry](https://twitter.com/jongleberry)\n- Team: @koajs/compress\n\n## Options\n\n### filter\\\u003cFunction\\\u003e\n\n```ts\nfunction (mimeType: string): Boolean {\n\n}\n```\n\nAn optional function that checks the response content type to decide whether to compress.\nBy default, it uses [compressible](https://github.com/jshttp/compressible).\n\n### options.threshold\\\u003cString|Number|Function\\\u003e\n\nMinimum response size in bytes to compress or a function that returns such response (see below).\nDefault `1024` bytes or `1kb`.\n\n### options[encoding]\\\u003cObject|Function\\\u003e\n\nThe current encodings are, in order of preference: `br`, `zstd`, `gzip`, `deflate`.\nSetting `options[encoding] = {}` will pass those options to the encoding function.\nSetting `options[encoding] = false` will disable that encoding.\n\nIt can be a function that returns options (see below).\n\n#### options.br\n\n[Brotli compression](https://en.wikipedia.org/wiki/Brotli) is supported in node v11.7.0+, which includes it natively.\nAs of v5.1.0, the default quality level is 4 for performance reasons.\n\n#### options.zstd\n\n[Zstandard compression](https://en.wikipedia.org/wiki/Zstandard) is natively supported in the Node.js API. Minimum supported version: `v22.15.0` (LTS); also available on the Current line starting from `v23.8.0+`. This middleware performs runtime feature detection for `zlib.createZstdCompress`; if present, Zstd is enabled, otherwise it is skipped—no version configuration required.\n\n### options.defaultEncoding\\\u003cString\\\u003e\n\nAn optional string, which specifies what encoders to use for requests without\n[Accept-Encoding](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding).\nDefault `identity`.\n\nThe standard dictates to treat such requests as `*` meaning that all compressions are permissible,\nyet it causes very practical problems when debugging servers with manual tools like `curl`, `wget`, and so on.\nIf you want to enable the standard behavior, just set `defaultEncoding` to `*`.\n\n## Manually turning compression on and off\n\nYou can always enable compression by setting `ctx.compress = true`.\nYou can always disable compression by setting `ctx.compress = false`.\nThis bypasses the filter check.\n\n```js\napp.use((ctx, next) =\u003e {\n  ctx.compress = true;\n  ctx.body = fs.createReadStream(file);\n});\n```\n\n`ctx.compress` can be an object similar to `options` above, whose properties (`threshold` and encoding options)\noverride the global `options` for this response and bypass the filter check.\n\n## Functional properties\n\nCertain properties (`threshold` and encoding options) can be specified as functions. Such functions will be called\nfor every response with three arguments:\n\n- `type` \u0026mdash; the same as `ctx.response.type` (provided for convenience)\n- `size` \u0026mdash; the same as `ctx.response.length` (provided for convenience)\n- `ctx` \u0026mdash; the whole context object, if you want to do something unique\n\nIt should return a valid value for that property. It is possible to return a function of the same shape,\nwhich will be used to calculate the actual property.\n\nExample:\n\n```js\napp.use((ctx, next) =\u003e {\n  // ...\n  ctx.compress = (type, size, ctx) =\u003e ({\n    br: size \u0026\u0026 size \u003e= 65536,\n    gzip: size \u0026\u0026 size \u003c 65536,\n  });\n  ctx.body = payload;\n});\n```\n\nRead all about `ctx` in https://koajs.com/#context and `ctx.response` in https://koajs.com/#response\n","funding_links":[],"categories":["Middleware","仓库"],"sub_categories":["中间件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fcompress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Fcompress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fcompress/lists"}