{"_id":"@derodero24/comprs-middleware","_rev":"2-f16ed6ccc7205cbd029a6c320f346039","name":"@derodero24/comprs-middleware","dist-tags":{"latest":"1.0.0"},"versions":{"0.3.0":{"name":"@derodero24/comprs-middleware","version":"0.3.0","keywords":["compression","middleware","express","fastify","hono","zstd","brotli","gzip","http","content-encoding"],"author":{"name":"derodero24"},"license":"MIT","_id":"@derodero24/comprs-middleware@0.3.0","maintainers":[{"name":"derodero24","email":"k.itsh20524abc@gmail.com"}],"homepage":"https://github.com/derodero24/comprs/tree/develop/packages/middleware","bugs":{"url":"https://github.com/derodero24/comprs/issues"},"dist":{"shasum":"48a765defaa69a82fcbf3761d27fddd6c3f69f1f","tarball":"https://registry.npmjs.org/@derodero24/comprs-middleware/-/comprs-middleware-0.3.0.tgz","fileCount":18,"integrity":"sha512-K8zC+jJ9Lac0SvfyPCwcWJJYP+YlXA/Q3ipHRD0PDDEEg02LteGSj2ofSp9/ytssL8Thh7xN+uJfxdngILMnBg==","signatures":[{"sig":"MEUCIQCITbmrY6UBIJXDVgRPyB04hepD6BUrGJZ/q2LzQkQ4hAIgTpFV8WqtBScePAriE69rPkXaL8KHHX4+zSKQVXnBCZ4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@derodero24%2fcomprs-middleware@0.3.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":27408},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","engines":{"node":">=20.0.0"},"exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./hono":{"import":{"types":"./dist/hono.d.ts","default":"./dist/hono.js"}},"./express":{"import":{"types":"./dist/express.d.ts","default":"./dist/express.js"}},"./fastify":{"import":{"types":"./dist/fastify.d.ts","default":"./dist/fastify.js"}}},"gitHead":"ee9742d9040baa66a1451a148dc1213b29cffdff","scripts":{"test":"vitest run","build":"tsc","check":"biome ci","typecheck":"tsc --noEmit"},"_npmUser":{"name":"derodero24","email":"k.itsh20524abc@gmail.com"},"repository":{"url":"git+https://github.com/derodero24/comprs.git","type":"git","directory":"packages/middleware"},"_npmVersion":"11.11.0","description":"HTTP compression middleware powered by comprs. Supports Express, Fastify, and Hono with zstd, brotli, gzip, and deflate.","directories":{},"sideEffects":false,"_nodeVersion":"24.14.1","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"hono":"^4.0.0","vitest":"^4.1.0","express":"^5.1.0","fastify":"^5.0.0","typescript":"^6.0.0","@types/express":"^5.0.0","@derodero24/comprs":"workspace:*"},"peerDependencies":{"hono":"^4.0.0","express":"^4.21.0 || ^5.0.0","fastify":"^5.0.0","@derodero24/comprs":"^1.0.0"},"peerDependenciesMeta":{"hono":{"optional":true},"express":{"optional":true},"fastify":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/comprs-middleware_0.3.0_1776001450025_0.26783172499901453","host":"s3://npm-registry-packages-npm-production"}},"1.0.0":{"name":"@derodero24/comprs-middleware","version":"1.0.0","description":"HTTP compression middleware powered by comprs. Supports Express, Fastify, and Hono with zstd, brotli, gzip, and deflate.","license":"MIT","author":{"name":"derodero24"},"repository":{"type":"git","url":"git+https://github.com/derodero24/comprs.git","directory":"packages/middleware"},"homepage":"https://github.com/derodero24/comprs/tree/develop/packages/middleware","bugs":{"url":"https://github.com/derodero24/comprs/issues"},"keywords":["compression","middleware","express","fastify","hono","zstd","brotli","gzip","http","content-encoding"],"sideEffects":false,"type":"module","main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./express":{"import":{"types":"./dist/express.d.ts","default":"./dist/express.js"}},"./fastify":{"import":{"types":"./dist/fastify.d.ts","default":"./dist/fastify.js"}},"./hono":{"import":{"types":"./dist/hono.d.ts","default":"./dist/hono.js"}}},"engines":{"node":">=22.0.0"},"scripts":{"build":"tsc","check":"biome ci","typecheck":"tsc --noEmit","test":"vitest run"},"peerDependencies":{"@derodero24/comprs":"^2.0.0","express":"^4.21.0 || ^5.0.0","fastify":"^5.0.0","hono":"^4.0.0"},"peerDependenciesMeta":{"express":{"optional":true},"fastify":{"optional":true},"hono":{"optional":true}},"devDependencies":{"@derodero24/comprs":"workspace:*","@types/express":"^5.0.0","express":"^5.1.0","fastify":"^5.0.0","hono":"^4.0.0","typescript":"^6.0.0","vitest":"^4.1.0"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"gitHead":"cd95c7a42f9fd0ff4c9e50129b0b573122db5db0","_id":"@derodero24/comprs-middleware@1.0.0","_nodeVersion":"24.14.1","_npmVersion":"11.11.0","dist":{"integrity":"sha512-ZtxMXNRCF8z+wg1Dbs+ZX0L0m7wlVVwkQ7Zvbej7vTC52H42pUVow8d7gZ5BKemRmGX+u5VKbAVwT8+/KRLGxw==","shasum":"e50d27616a34d7ea1987ece4b5048e281bdd5d29","tarball":"https://registry.npmjs.org/@derodero24/comprs-middleware/-/comprs-middleware-1.0.0.tgz","fileCount":18,"unpackedSize":27408,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@derodero24%2fcomprs-middleware@1.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDLfI/Dr+s2WieFBlFVwUB4/57+6KUJzt85OGectOA4rQIhAOCnGwp6COYgc76M6LC1TwSmdGvMklRlJzT1rIyoSab4"}]},"_npmUser":{"name":"derodero24","email":"k.itsh20524abc@gmail.com"},"directories":{},"maintainers":[{"name":"derodero24","email":"k.itsh20524abc@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/comprs-middleware_1.0.0_1777883726659_0.6020305726121387"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-12T13:44:09.941Z","modified":"2026-05-04T08:35:27.083Z","0.3.0":"2026-04-12T13:44:10.184Z","1.0.0":"2026-05-04T08:35:26.789Z"},"bugs":{"url":"https://github.com/derodero24/comprs/issues"},"author":{"name":"derodero24"},"license":"MIT","homepage":"https://github.com/derodero24/comprs/tree/develop/packages/middleware","keywords":["compression","middleware","express","fastify","hono","zstd","brotli","gzip","http","content-encoding"],"repository":{"type":"git","url":"git+https://github.com/derodero24/comprs.git","directory":"packages/middleware"},"description":"HTTP compression middleware powered by comprs. Supports Express, Fastify, and Hono with zstd, brotli, gzip, and deflate.","maintainers":[{"name":"derodero24","email":"k.itsh20524abc@gmail.com"}],"readme":"# @derodero24/comprs-middleware\n\nHTTP compression middleware powered by [comprs](https://github.com/derodero24/comprs). Supports **Express**, **Fastify**, and **Hono** with **zstd**, **brotli**, **gzip**, and **deflate**.\n\n## Features\n\n- **Multi-framework** — Express, Fastify, and Hono via subpath imports\n- **zstd, brotli, gzip, deflate** — all algorithms via a single package\n- **Accept-Encoding negotiation** — automatically selects the best encoding\n- **Configurable priority** — control which algorithm is preferred\n- **Threshold support** — skip compression for small responses\n- **Content-Type filtering** — only compresses known compressible types; skips responses without a Content-Type header\n- **Rust-powered** — uses comprs native bindings for maximum throughput\n\n## Installation\n\n```bash\nnpm install @derodero24/comprs @derodero24/comprs-middleware\n```\n\n## Usage\n\n### Express\n\n```ts\nimport express from 'express';\nimport { comprs } from '@derodero24/comprs-middleware/express';\n\nconst app = express();\napp.use(comprs());\n```\n\n### Fastify\n\n```ts\nimport Fastify from 'fastify';\nimport { comprs } from '@derodero24/comprs-middleware/fastify';\n\nconst app = Fastify();\napp.register(comprs);\n```\n\n### Hono\n\n```ts\nimport { Hono } from 'hono';\nimport { comprs } from '@derodero24/comprs-middleware/hono';\n\nconst app = new Hono();\napp.use(comprs());\n```\n\n### Options\n\nAll adapters accept the same core options:\n\n```ts\ncomprs({\n  encodings: ['zstd', 'br', 'gzip'],   // Algorithm priority\n  threshold: 512,                        // Min response size (bytes)\n  level: { zstd: 3, br: 6, gzip: 6 },  // Per-algorithm levels\n  filter: (req, res) => true,            // Custom filter (Express/Fastify)\n})\n```\n\n## API\n\n### Subpath exports\n\n| Import path | Framework | Returns |\n|-------------|-----------|---------|\n| `@derodero24/comprs-middleware/express` | Express/Connect | `(req, res, next) => void` |\n| `@derodero24/comprs-middleware/fastify` | Fastify | `FastifyPluginAsync` |\n| `@derodero24/comprs-middleware/hono` | Hono | `MiddlewareHandler` |\n| `@derodero24/comprs-middleware` | — | `negotiate()`, types |\n\n### Option reference\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `encodings` | `Encoding[]` | `['zstd', 'br', 'gzip', 'deflate']` | Algorithm priority order |\n| `threshold` | `number` | `1024` | Minimum response size (bytes) to compress |\n| `level` | `LevelOptions` | `{}` | Per-algorithm compression levels |\n| `filter` | `(req, res) => boolean` | Compressible types | Custom filter (Express/Fastify) |\n\n> Hono adapter accepts `filter: (c: Context) => boolean` instead.\n\n### `negotiate(acceptEncoding, preferred?)`\n\nLow-level Accept-Encoding negotiation. Returns the best encoding or `null`.\n\n```ts\nimport { negotiate } from '@derodero24/comprs-middleware';\n\nnegotiate('gzip, br;q=0.8, zstd');\n// => 'zstd' (highest server preference accepted by client)\n```\n\n## Behavior\n\nAll adapters automatically:\n\n- Set `Content-Encoding` header\n- Remove `Content-Length` (compressed size is unknown)\n- Set `Vary: Accept-Encoding` for caching correctness\n- Skip compression when:\n  - Response already has `Content-Encoding`\n  - `Cache-Control: no-transform` is set\n  - Content-Type is not compressible (images, etc.)\n  - Content-Type is not set\n  - Response body is below threshold\n  - Request method is `HEAD`\n  - Client does not accept any supported encoding\n\n## License\n\n[MIT](../../LICENSE)\n","readmeFilename":"README.md"}