{"name":"compress-utils","version":"0.7.1","keywords":["compression","decompression","wasm","webassembly","zstd","brotli","zlib","gzip","bzip2","lz4","xz","lzma"],"author":{"url":"https://nico.codes","name":"Nicolas Dupont","email":"nico@dupont.live"},"license":"MIT","_id":"compress-utils@0.7.1","maintainers":[{"name":"dupontcyborg","email":"nico@dupont.live"}],"homepage":"https://github.com/dupontcyborg/compress-utils#readme","bugs":{"url":"https://github.com/dupontcyborg/compress-utils/issues"},"dist":{"shasum":"dfbc28165e6d1732ece78d7a0f5072cccd8e8b91","tarball":"http://registry-npm.ywwl.com/compress-utils/download/compress-utils-0.7.1.tgz","fileCount":61,"integrity":"sha512-TMmTeUh0pQwnG8HoBDHe9q6uCcWQxPxaifQ820inQ0933NJH8uer4KmLCCpKYP3ytd1KZpWRwf/+jBOJVaETJA==","signatures":[{"sig":"MEUCIQDDQpQ1X6IXZjQSj+XFQa0EvGRgQD6DOZWBxJa7Ewmi1wIgZtiGF9iDKrygh0WZj64sY3MlHN3VJYK/XWA6ka7i3EU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/compress-utils@0.7.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":1821283,"size":694276,"noattachment":false,"key":"/compress-utils/-/compress-utils-0.7.1.tgz"},"type":"module","engines":{"node":">=18"},"exports":{"./xz":"./dist/algorithms/xz/index.js","./bz2":"./dist/algorithms/bz2/index.js","./lz4":"./dist/algorithms/lz4/index.js","./zlib":"./dist/algorithms/zlib/index.js","./zstd":"./dist/algorithms/zstd/index.js","./brotli":"./dist/algorithms/brotli/index.js"},"gitHead":"27a59b4ea4cf0e205ec92bd5e8f73c478ca46e57","imports":{"#resolver":{"bun":"./dist/core/resolve-browser.js","deno":"./dist/core/resolve-browser.js","node":"./dist/core/resolve-node.js","types":"./src/core/resolve-default.ts","browser":"./dist/core/resolve-browser.js","default":"./dist/core/resolve-default.js"}},"scripts":{"lint":"biome lint .","test":"vitest run","build":"npm run build:wasm && npm run build:ts","check":"biome check .","format":"biome format --write .","build:ts":"tsc -p tsconfig.json","lint:fix":"biome lint --write .","test:bun":"bun test --bun tests/","test:deno":"deno run --allow-read --allow-env tests-runtime/deno-smoke.ts","build:wasm":"cmake -S ../.. -B ../../build-wasm -DBUILD_WASM_BINDINGS=ON -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_CPP_BINDINGS=OFF -DENABLE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release && cmake --build ../../build-wasm --target compress_utils_wasm -j","test:watch":"vitest","test:browser":"playwright test"},"_npmUser":{"name":"dupontcyborg","email":"nico@dupont.live"},"repository":{"url":"git+https://github.com/dupontcyborg/compress-utils.git","type":"git","directory":"bindings/wasm"},"_npmVersion":"10.9.7","description":"WASM compression bindings for zstd, brotli, zlib, bz2, lz4, xz - all tree-shakeable.","directories":{},"sideEffects":false,"_nodeVersion":"22.22.2","publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^4.1.6","esbuild":"^0.28.0","typescript":"^5.5.0","@types/node":"^25.8.0","@biomejs/biome":"2.4.15","@playwright/test":"^1.60.0"},"_npmOperationalInternal":{"tmp":"tmp/compress-utils_0.7.1_1779051530370_0.7032908315058137","host":"s3://npm-registry-packages-npm-production"},"readme":"# compress-utils\n\n[![npm version](https://img.shields.io/npm/v/compress-utils.svg)](https://www.npmjs.com/package/compress-utils)\n[![npm downloads](https://img.shields.io/npm/dm/compress-utils.svg)](https://www.npmjs.com/package/compress-utils)\n[![types: built-in](https://img.shields.io/badge/types-built--in-blue.svg)](https://www.npmjs.com/package/compress-utils)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nUnified WebAssembly bindings for eight compression algorithms: Brotli, bzip2, LZ4, XZ/LZMA, zlib, Zstandard, Snappy, and gzip. Same API for every algorithm, in every JavaScript runtime, with tree-shakeable imports so bundlers ship only what you use.\n\n## Installation\n\n```bash\nnpm install compress-utils\n# or: pnpm add / yarn add / bun add / deno add npm:compress-utils\n```\n\n### CDN (no bundler)\n\nThe package is published as ESM. You can pull it straight from a CDN — no install step, no build step.\n\n```html\n<script type=\"module\">\n    import { compress, decompress } from \n      \"https://esm.sh/compress-utils/zstd\";\n\n    const out = await compress(\n      new TextEncoder().encode(\"hello\")\n      );\n</script>\n```\n\n| CDN        | Per-algo URL                                                          |\n|------------|-----------------------------------------------------------------------|\n| esm.sh     | `https://esm.sh/compress-utils/<algo>`                                |\n| jsDelivr   | `https://cdn.jsdelivr.net/npm/compress-utils/dist/algorithms/<algo>/index.js` |\n| unpkg      | `https://unpkg.com/compress-utils/dist/algorithms/<algo>/index.js`    |\n\n## Quick start\n\nEach algorithm is its own subpath import. Pick the one you need; the rest stay out of your bundle.\n\n```ts\nimport { compress, decompress } from \"compress-utils/zstd\";\n\nconst input = new TextEncoder().encode(\"the quick brown fox \" .repeat(50));\n\nconst compressed = await compress(input, { level: 9 });\nconst restored   = await decompress(compressed);\n```\n\nAvailable subpaths: `compress-utils/zstd`, `/brotli`, `/zlib`, `/bz2`, `/lz4`, `/xz`, `/snappy`, `/gzip`. Identical surface across all eight. Each also has `/<algo>/decompress` and `/<algo>/compress` variants that ship only one direction for a much smaller `.wasm` — see [Bundle size](#bundle-size).\n\n### Web Streams\n\n```ts\nimport { compressionStream, decompressionStream } from \"compress-utils/zstd\";\n\nawait fetch(\"/big-file.json\")\n    .then(r => r.body!.pipeThrough(compressionStream({ level: 3 })))\n    .then(s => s.pipeTo(uploadDestination));\n```\n\n### Manual streaming (with `using` for auto-cleanup)\n\n```ts\nimport { createCompressStream } from \"compress-utils/brotli\";\n\nusing cs = await createCompressStream({ level: 5 });\nconst chunks: Uint8Array[] = [];\nfor (const chunk of input) chunks.push(cs.write(chunk));\nchunks.push(cs.finish());\n// cs is destroyed automatically on scope exit (TS 5.2+ / Node 22+).\n```\n\nIf `using` isn't available in your toolchain, call `cs.destroy()` explicitly — or rely on the GC backstop (a `FinalizationRegistry` frees the C-side handle eventually).\n\n## Supported algorithms\n\n| Algorithm | Subpath                  | Wire format produced                       |\n|-----------|--------------------------|--------------------------------------------|\n| zlib      | `compress-utils/zlib`    | zlib wrapper (RFC 1950)                    |\n| bzip2     | `compress-utils/bz2`     | bzip2 stream                               |\n| XZ/LZMA   | `compress-utils/xz`      | XZ stream with CRC64                       |\n| LZ4       | `compress-utils/lz4`     | LZ4 frame (compatible with `.lz4` files)   |\n| Zstandard | `compress-utils/zstd`    | ZSTD frame with content size               |\n| Brotli    | `compress-utils/brotli`  | raw Brotli stream                          |\n| Snappy    | `compress-utils/snappy`  | Raw Snappy block                           |\n| gzip      | `compress-utils/gzip`    | gzip stream (RFC 1952)                     |\n| LZO       | `compress-utils/lzo/decompress` | Raw LZO1X block (decompress only; pass `{expectedSize}` as output capacity) |\n\nImports are independent — `import \"compress-utils/zstd\"` and `import \"compress-utils/brotli\"` pull in two separate `.wasm` modules, not a combined bundle. Files marked `\"sideEffects\": false` so unused exports are tree-shaken aggressively. For per-module `.wasm` sizes (and the smaller decode-only / encode-only builds), see **[Bundle size](#bundle-size)**.\n\n## Bundle size\n\nImporting `compress-utils/<algo>` gives you the **full** codec — compress *and* decompress. If you only need one direction (a browser that just *decompresses* fetched assets is the common case), import a directional subpath and the other half is dead-stripped from the `.wasm` entirely:\n\n```ts\n// decoder only, 90 KB\nimport { decompress } from \"compress-utils/zstd/decompress\"; \n\n// or, encoder only:\nimport { compress }   from \"compress-utils/zstd/compress\";\n```\n\n- **`/decompress`** exposes `decompress`, `createDecompressStream`, `decompressionStream`, `setMaxDecompressedSize`, `version`.\n- **`/compress`** exposes `compress`, `createCompressStream`, `compressionStream`, `version`.\n- The default subpath keeps **both**\n\nComparison of the gzipped sizes:\n\n| algo   | full          | decompress-only       | compress-only         |\n|--------|--------------:|----------------------:|----------------------:|\n| zstd   | 128K  | 36K    | 106K           |\n| brotli | 169K  | 84K    | 154K           |\n| lz4    | 39K   | 15K    | 35K             |\n| bz2    | 33K   | 22K    | 25K             |\n| xz     | 62K   | 43K    | 51K            |\n| zlib   | 33K   | 25K    | 26K             |\n| snappy | 36K   | 32K    | 28K             |\n| gzip   | 80K   | 52K    | 60K             |\n\nThe `.wasm` is the bulk of what ships; the JS glue is a few KB, shared, and tree-shaken to the methods you import.\n\n## Compression levels\n\nEvery algorithm accepts a `level` from **1 (fastest) to 10 (smallest)**. The binding maps that to each algorithm's native range internally — you don't need to know that Zstandard goes 1–22 or zlib goes 1–9. Defaults to `5`.\n\n```ts\nawait compress(input, { level: 1 });   // fastest\nawait compress(input, { level: 10 });  // smallest\n```\n\n## Runtime support\n\nTested in CI on every release:\n\n| Runtime              | Status |\n|----------------------|--------|\n| Node 20, 22, 24      | ✅     |\n| Bun                  | ✅     |\n| Deno 2.x             | ✅     |\n| Chromium / Firefox / WebKit (Playwright) | ✅ |\n\n## TypeScript\n\nThe package is TypeScript-first. `.d.ts` files ship alongside the JS for every subpath; no `@types/` package needed.\n\n```ts\nimport { compress, type CompressOptions, type CompressError } from \"compress-utils/zstd\";\n\nconst opts: CompressOptions = { level: 7 };\nconst compressed: Uint8Array = await compress(input, opts);\n```\n\n## Preloading and synchronous calls\n\nEach algorithm and direction-specific subpath exports `preload()`. It loads and\ninitializes that subpath's WASM module once; concurrent calls share initialization.\nA failed initialization can be retried. No codec work is performed by preload.\n\n```ts\nimport { preload, compressSync, decompressSync } from \"compress-utils/zlib\";\nawait preload();\nconst compressed = compressSync(new TextEncoder().encode(\"hello\"));\nconst restored = decompressSync(compressed);\n```\n\n`compressSync`, `decompressSync`, `createCompressStreamSync`, and\n`createDecompressStreamSync` are available for the directions exposed by the\nsubpath. They throw with a `preload()` instruction before initialization completes.\nExisting asynchronous APIs initialize automatically and also enable subsequent\nsynchronous calls. Initializing one subpath does not initialize another: encoder\nand decoder subpaths use different WASM modules. Sync calls block the calling\nthread; use a worker for expensive operations.\n\n## License\n\nMIT. See [LICENSE](https://github.com/dupontcyborg/compress-utils/blob/main/LICENSE).\n\n---\n\nBuilt by [Nico Dupont](https://nico.codes).\n","publish_time":1779051530572,"_cnpm_publish_time":1779051530572,"dist-tags":{"latest":"0.12.1"}}