{"_id":"@addmaple/lz4","_rev":"4-b9bdea9065cbf324d8e48dfa5daa6bf3","name":"@addmaple/lz4","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"@addmaple/lz4","version":"0.1.0","keywords":["lz4","compression","wasm","browser"],"license":"MIT","_id":"@addmaple/lz4@0.1.0","maintainers":[{"name":"hitradostava","email":"nick@addmaple.com"}],"homepage":"https://github.com/addmaple/wasm-fast-compress#readme","bugs":{"url":"https://github.com/addmaple/wasm-fast-compress/issues"},"dist":{"shasum":"4171c6b70ba2e0429b13c933f64ac38783fcea8e","tarball":"https://registry.npmjs.org/@addmaple/lz4/-/lz4-0.1.0.tgz","fileCount":18,"integrity":"sha512-YyN2/qk4BoPzS/yIHZFKtIRnpmSyg9y0vak6vElopKgEfPdPpD+uY/bzITwHYT8cGXC0osjeLSxugczgGuSqkA==","signatures":[{"sig":"MEUCIFtvS+un5xMDdN0cUZBA2c3lZv7zEL6HhFLF+Y/eQkZZAiEAgf95ndvotmFmjrTfUs5n2RHehNu2BaTUW65m9hAvb+U=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":354612},"main":"./dist/node.js","type":"module","types":"./dist/node.d.ts","browser":"./dist/browser.js","exports":{".":{"node":"./dist/node.js","browser":"./dist/browser.js","default":"./dist/node.js"},"./inline":{"node":"./dist/node-inline.js","browser":"./dist/browser-inline.js","default":"./dist/node-inline.js"}},"gitHead":"cfc1c158ae4568e1cf553ce90d1ea340d3c32c34","scripts":{},"_npmUser":{"name":"hitradostava","email":"nick@addmaple.com"},"repository":{"url":"git+https://github.com/addmaple/wasm-fast-compress.git","type":"git","directory":"js/lz4"},"_npmVersion":"10.9.3","description":"Fast lz4 compression in the browser using Rust + WASM","directories":{},"_nodeVersion":"22.19.0","dependencies":{"lz4js":"^0.2.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/lz4_0.1.0_1766411308972_0.358547993193276","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@addmaple/lz4","version":"0.1.1","keywords":["lz4","compression","wasm","browser"],"license":"MIT","_id":"@addmaple/lz4@0.1.1","maintainers":[{"name":"hitradostava","email":"nick@addmaple.com"}],"homepage":"https://github.com/addmaple/wasm-fast-compress#readme","bugs":{"url":"https://github.com/addmaple/wasm-fast-compress/issues"},"dist":{"shasum":"5a2eab016db0043f41af412a5dd90c289805fd0f","tarball":"https://registry.npmjs.org/@addmaple/lz4/-/lz4-0.1.1.tgz","fileCount":18,"integrity":"sha512-qvNBop4fgukuLiPLkxIL4JOj47s33vyuRAKK5RdffVQmVQUUWr8uVUIUjT/xTuRE1GUailSoopWDBHmN/1d/tg==","signatures":[{"sig":"MEUCIAYjXI6UpDIUlVlwsMjJ8dBUwRv8ocChHZkuLg98bCfUAiEAn1cBAdvQACfYgX7ZxepCNxkMJhR2MF9Di9/iTIWMggE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":353621},"main":"./dist/node.js","type":"module","types":"./dist/node.d.ts","browser":"./dist/browser.js","exports":{".":{"node":"./dist/node.js","browser":"./dist/browser.js","default":"./dist/node.js"},"./inline":{"node":"./dist/node-inline.js","browser":"./dist/browser-inline.js","default":"./dist/node-inline.js"}},"gitHead":"1269fbf49631fd1f8ec2ae7a9389234802d16dc7","scripts":{},"_npmUser":{"name":"hitradostava","email":"nick@addmaple.com"},"repository":{"url":"git+https://github.com/addmaple/wasm-fast-compress.git","type":"git","directory":"js/lz4"},"_npmVersion":"10.9.3","description":"Fast lz4 compression in the browser using Rust + WASM","directories":{},"_nodeVersion":"22.19.0","dependencies":{"lz4js":"^0.2.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/lz4_0.1.1_1766412965119_0.8413708263152251","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@addmaple/lz4","version":"0.1.2","keywords":["lz4","compression","wasm","browser"],"license":"MIT","_id":"@addmaple/lz4@0.1.2","maintainers":[{"name":"hitradostava","email":"nick@addmaple.com"}],"homepage":"https://github.com/addmaple/wasm-fast-compress#readme","bugs":{"url":"https://github.com/addmaple/wasm-fast-compress/issues"},"dist":{"shasum":"6c45c1068e4829ce046e17e8b402de4b732342c6","tarball":"https://registry.npmjs.org/@addmaple/lz4/-/lz4-0.1.2.tgz","fileCount":18,"integrity":"sha512-mCYxwfcBdmxbbepQdIkhpvCpA+X24QqjEiFUPoR9GDrR8cKICXPZ9UdFu0q1j9emb1MQqlqgvrnpQFOfZKeP4w==","signatures":[{"sig":"MEQCIDnvQsD/EjROESfz65E4ZmCNPKqaPuyzCylo+E6PhL1FAiB784pufOAedqpr4JhFsPnZZr42lrWIf5msSKaFcPs52g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":610779},"main":"./dist/node.js","type":"module","types":"./dist/node.d.ts","browser":"./dist/browser.js","exports":{".":{"node":"./dist/node.js","browser":"./dist/browser.js","default":"./dist/node.js"},"./inline":{"node":"./dist/node-inline.js","browser":"./dist/browser-inline.js","default":"./dist/node-inline.js"}},"gitHead":"11414f4738730cd6c01ecb85a57e52afc1aa9cbd","scripts":{},"_npmUser":{"name":"hitradostava","email":"nick@addmaple.com"},"repository":{"url":"git+https://github.com/addmaple/wasm-fast-compress.git","type":"git","directory":"js/lz4"},"_npmVersion":"10.9.3","description":"Fast lz4 compression in the browser using Rust + WASM","directories":{},"_nodeVersion":"22.19.0","dependencies":{"lz4js":"^0.2.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/lz4_0.1.2_1767368456323_0.1330296545623395","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@addmaple/lz4","version":"0.2.0","type":"module","main":"./dist/node.js","browser":"./dist/browser.js","exports":{".":{"node":"./dist/node.js","browser":"./dist/browser.js","default":"./dist/node.js"},"./inline":{"node":"./dist/node-inline.js","browser":"./dist/browser-inline.js","default":"./dist/node-inline.js"}},"repository":{"type":"git","url":"git+https://github.com/addmaple/wasm-fast-compress.git","directory":"js/lz4"},"homepage":"https://github.com/addmaple/wasm-fast-compress#readme","scripts":{},"dependencies":{"lz4js":"^0.2.0"},"description":"Fast lz4 compression in the browser using Rust + WASM","keywords":["lz4","compression","wasm","browser"],"license":"MIT","_id":"@addmaple/lz4@0.2.0","gitHead":"84ff29bf2bd4ff0666c07aaa0122fe71317634de","types":"./dist/node.d.ts","bugs":{"url":"https://github.com/addmaple/wasm-fast-compress/issues"},"_nodeVersion":"22.19.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-2zK2F7Td1lKy+EMP3s/qzftmb7rR+b7T79OhUaXpDuKavWdwivgnidDIvH9oFuLqmfA9z4LUPZpIqHGnEzt00A==","shasum":"45ae0639b680c02ce02221685cdbd6064f3bb383","tarball":"https://registry.npmjs.org/@addmaple/lz4/-/lz4-0.2.0.tgz","fileCount":18,"unpackedSize":616186,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDRWswZWg1TgRAjIxPWfvtnXhXTkyLa/yBvXWsLuwRyGQIhAOJqfBmPDZGeXcruwTREhyyh3MU5lVMOw71AF107e08X"}]},"_npmUser":{"name":"hitradostava","email":"nick@addmaple.com"},"directories":{},"maintainers":[{"name":"hitradostava","email":"nick@addmaple.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/lz4_0.2.0_1768767626784_0.8081341410774026"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-22T13:48:28.850Z","modified":"2026-01-18T20:20:27.139Z","0.1.0":"2025-12-22T13:48:29.112Z","0.1.1":"2025-12-22T14:16:05.294Z","0.1.2":"2026-01-02T15:40:56.500Z","0.2.0":"2026-01-18T20:20:27.012Z"},"bugs":{"url":"https://github.com/addmaple/wasm-fast-compress/issues"},"license":"MIT","homepage":"https://github.com/addmaple/wasm-fast-compress#readme","keywords":["lz4","compression","wasm","browser"],"repository":{"type":"git","url":"git+https://github.com/addmaple/wasm-fast-compress.git","directory":"js/lz4"},"description":"Fast lz4 compression in the browser using Rust + WASM","maintainers":[{"name":"hitradostava","email":"nick@addmaple.com"}],"readme":"# @addmaple/lz4\n\nFast LZ4 compression in the browser and Node.js using Rust + WASM.\n\n**2.5x-3.5x faster** than `lz4js`.\n\n## Implementation (Rust)\n\nThis package is backed by these Rust crates in the `wasm-fast-compress` repo:\n\n- `codec-lz4` (this repo): high-level codec wrapper\n- `lz4_flex` (Git fork, branch `wasm-simd`): core LZ4 implementation with WASM SIMD128 hot paths\n\n## SIMD acceleration (how it works)\n\n- We build **two WASM binaries**:\n  - `lz4.base.wasm`: compiled without `+simd128`\n  - `lz4.simd.wasm`: compiled with `-C target-feature=+simd128`\n- At runtime, the JS loader detects SIMD support and loads the best binary automatically.\n\nOn wasm32, the SIMD build benefits from:\n- `lz4_flex` explicit `wasm32 + simd128` intrinsics for match finding / copying hot paths\n- additional LLVM autovectorization where applicable\n\n## Installation\n\n```bash\nnpm install @addmaple/lz4\n```\n\n## Usage\n\n```javascript\nimport { init, compress } from '@addmaple/lz4';\n\n// Optional: call init() to avoid first-call latency.\n// If you skip init(), the first compress/decompress call will lazy-initialize.\nawait init();\n\nconst input = new TextEncoder().encode('hello world');\nconst compressed = await compress(input);\n```\n\n### Lazy init (init() optional)\n\n```javascript\nimport { compress } from '@addmaple/lz4';\n\nconst input = new TextEncoder().encode('hello world');\nconst compressed = await compress(input); // triggers lazy init on first call\n```\n\n### Streaming compression + decompression\n\nFor chunked input (e.g. streaming over the network), use the handle-based streaming helpers:\n\n```javascript\nimport { init, StreamingCompressor, StreamingDecompressor } from '@addmaple/lz4';\n\n// Optional: init() is not required; streaming helpers also lazy-init.\nawait init();\n\n// Compress\nconst enc = new StreamingCompressor();\nconst c1 = await enc.compressChunk(chunk1, false);\nconst c2 = await enc.compressChunk(chunk2, false);\nconst c3 = await enc.compressChunk(chunk3, true); // finish\n\n// Decompress (finish must be true to produce output for frame format)\nconst dec = new StreamingDecompressor();\nawait dec.decompressChunk(c1, false);\nawait dec.decompressChunk(c2, false);\nconst plain = await dec.decompressChunk(c3, true);\n```\n\n### Streaming to `fetch()` (ergonomic)\n\nIf you want to upload a `File`/`Blob` with LZ4 compression, you can pipe it through the built-in stream helper:\n\n```javascript\nimport { createCompressionStream } from '@addmaple/lz4';\n\nconst body = file.stream().pipeThrough(createCompressionStream());\n\nawait fetch('/upload', {\n  method: 'POST',\n  headers: {\n    // Not a standard encoding token like gzip; your server must explicitly support this.\n    'Content-Encoding': 'lz4',\n  },\n  body,\n  // Needed for streaming request bodies in some runtimes (notably Node fetch).\n  duplex: 'half',\n});\n```\n\n### Streaming decompression from `fetch()` (ergonomic)\n\n```javascript\nimport { createDecompressionStream } from '@addmaple/lz4';\n\nconst res = await fetch('/download');\nif (!res.body) throw new Error('No response body');\n\nconst decompressed = res.body.pipeThrough(createDecompressionStream());\n\n// Example: read it all (or pipe somewhere else)\nconst buf = await new Response(decompressed).arrayBuffer();\n```\n\n### Inline (Zero-latency)\n\nWASM bytes embedded directly in JS — no separate file fetching:\n\n```javascript\nimport { init, compress } from '@addmaple/lz4/inline';\n\nawait init();\nconst compressed = await compress(input);\n```\n\n## API\n\n### `init()`\nInitialize the WASM module.\n\n### `compress(input)`\n- `input`: `Uint8Array`\n- Returns: `Promise<Uint8Array>`\n\nNote: LZ4 is a single-speed algorithm optimized for maximum throughput. Unlike Brotli/Gzip, it doesn't have compression levels.\n\n## Sponsor\n\nDevelopment of this module was sponsored by [addmaple.com](https://addmaple.com) — a modern data analysis platform.\n\n## License\n\nMIT\n\n","readmeFilename":"README.md"}