{"id":16088,"library":"inflation","title":"HTTP Stream Decompression","description":"Inflation is a focused utility that automatically decompresses HTTP streams using Node.js's built-in zlib module. It supports common compression algorithms like gzip, deflate, and brotli. Currently at version 2.1.0, the package demonstrates a stable, low-maintenance release cadence, with its last publish two years ago. It's widely adopted, with over 1.5 million dependents, indicating its reliability for its specific function. Its key differentiator is its simplicity and direct integration with Node.js streams for handling `Content-Encoding` headers, aiming to simplify the process of consuming compressed HTTP request bodies or responses without needing to manually detect the compression type. While robust for its core purpose, users should be aware of specific Node.js version requirements, especially for Brotli support.","status":"maintenance","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/stream-utils/inflation","tags":["javascript","decompress","unzip","inflate","zlib","gunzip","brotli"],"install":[{"cmd":"npm install inflation","lang":"bash","label":"npm"},{"cmd":"yarn add inflation","lang":"bash","label":"yarn"},{"cmd":"pnpm add inflation","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS (CJS) only. For use in an ESM module, you must use `import { createRequire } from 'module'; const require = createRequire(import.meta.url);` before requiring the package.","wrong":"import inflate from 'inflation'","symbol":"inflate","correct":"const inflate = require('inflation')"},{"note":"This is the correct pattern for importing 'inflation' (a CJS module) into an ES Module (ESM) context in Node.js.","symbol":"inflate","correct":"import { createRequire } from 'module';\nconst require = createRequire(import.meta.url);\nconst inflate = require('inflation');"},{"note":"When using TypeScript with CommonJS, `require('inflation')` is the standard way. If `esModuleInterop` is enabled, `import inflate from 'inflation'` might work, but the explicit `require` is more robust for CJS-only libraries.","symbol":"inflate","correct":"const inflate = require('inflation');"}],"quickstart":{"code":"const inflate = require('inflation');\nconst raw = require('raw-body');\nconst http = require('http');\n\n// Minimal HTTP server demonstrating stream decompression\nhttp.createServer(function (req, res) {\n  // Assume 'raw-body' is installed for this example: npm i raw-body\n  // For simplicity, we are not handling response ending or error cases robustly.\n  // In a real application, proper error handling and response management are crucial.\n  raw(inflate(req), 'utf-8', function (err, string) {\n    if (err) {\n      console.error('Error reading inflated body:', err);\n      res.statusCode = 500;\n      res.end('Error processing request body');\n      return;\n    }\n    console.log('Received inflated body:', string);\n    res.statusCode = 200;\n    res.setHeader('Content-Type', 'text/plain');\n    res.end(`Processed body length: ${string.length}`);\n  });\n}).listen(3000, () => {\n  console.log('Server listening on http://localhost:3000');\n  console.log('Send a compressed POST request to test (e.g., with Content-Encoding: gzip)');\n});","lang":"javascript","description":"This quickstart sets up a basic HTTP server that listens for incoming requests. It uses `inflation` to automatically decompress the request body based on the `Content-Encoding` header, then reads the raw content and logs it to the console. This demonstrates how to integrate `inflation` into an HTTP request processing pipeline for handling compressed data. Note that `raw-body` is used here for convenience in reading the stream, but is not a dependency of `inflation` itself."},"warnings":[{"fix":"Ensure your Node.js runtime is v11.7.0 or higher if Brotli decompression is required. For older Node.js versions, only gzip and deflate are reliably supported.","message":"Brotli decompression, while listed as an option, requires Node.js v11.7.0 or newer. The `engines` field in `package.json` (`>= 0.8.0`) is misleading for Brotli compatibility, as versions between 0.8.0 and 11.6.x do not support Brotli natively. Attempting to decompress Brotli streams on older Node.js versions will result in runtime errors.","severity":"gotcha","affected_versions":"<11.7.0"},{"fix":"For ESM projects, use `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const inflate = require('inflation');` or configure your build system to transpile CJS modules.","message":"The `inflation` package is a CommonJS (CJS) module. Direct `import` statements in ES Module (ESM) contexts will fail unless a compatibility layer like `import { createRequire } from 'module'` is used.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always explicitly pass the `encoding` option to `inflate(stream, { encoding: 'gzip' })` if the input stream is not an `http.IncomingMessage` or similar object with a `headers` property.","message":"If the `encoding` option is not explicitly provided, `inflation` attempts to read `stream.headers['content-encoding']`. If the input `stream` does not have a `headers` property (e.g., it's a generic Readable stream, not an `http.IncomingMessage`), decompression may not occur as expected or could lead to errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Upgrade your Node.js runtime to v11.7.0 or newer to support Brotli decompression.","cause":"Attempting to decompress a Brotli stream on a Node.js version older than v11.7.0.","error":"Error: Brotli: invalid result"},{"fix":"Pass the `encoding` option explicitly: `inflate(myStream, { encoding: 'gzip' })` or ensure the `stream` object has a `headers` property containing `content-encoding`.","cause":"The `inflation` function tried to access `stream.headers['content-encoding']` because no `encoding` option was provided, but the input `stream` object did not have a `headers` property.","error":"TypeError: Cannot read properties of undefined (reading 'content-encoding')"},{"fix":"Use `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const inflate = require('inflation');` for ESM projects to import this CJS-only package.","cause":"Trying to `require()` an ES Module or using `import` for a CJS module without proper setup in an ESM context.","error":"ERR_REQUIRE_ESM: require() of ES Module ... from ... not supported."}],"ecosystem":"npm"}