{"name":"hysnappy","version":"1.1.1","description":"fast and tiny snappy compression in wasm","author":{"name":"Hyperparam"},"homepage":"https://hyperparam.app","keywords":["snappy","codec","compress","compression","compressor","decompress","decompression","decompressor","hyperparam","hyparquet","parquet","wasm","webassembly"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/hyparam/hysnappy.git"},"type":"module","types":"js/index.d.ts","main":"js/index.js","sideEffects":false,"scripts":{"coverage":"vitest run --coverage","lint":"eslint .","lint:fix":"eslint . --fix","test":"vitest run"},"devDependencies":{"@types/node":"25.3.0","@vitest/coverage-v8":"4.0.18","eslint":"9.39.2","eslint-plugin-jsdoc":"62.7.0","typescript":"5.9.3","vitest":"4.0.18"},"_id":"hysnappy@1.1.1","gitHead":"fab2cda3910eea3d13dd69375de16a2100131285","bugs":{"url":"https://github.com/hyparam/hysnappy/issues"},"_nodeVersion":"24.13.1","_npmVersion":"11.3.0","dist":{"integrity":"sha512-/V9XcN2NtRyWjR4LYMfvnvasVVF8jbT/ej0eofBQjZel91E3D813FQ3mQC6gDSMMTCq/FJh28XHeyqr3I/oBRw==","shasum":"30b688c94f6537e418f8b502a7e65cdc0b942341","tarball":"http://registry-npm.ywwl.com/hysnappy/download/hysnappy-1.1.1.tgz","fileCount":7,"unpackedSize":19075,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC+Pfc5ROZ6oVBJ6KzvqW3zioOlKf97UIGhYoj45dhb8wIhALHPqRDJxjHMX7QuLTk1aMG4sHFHGh/PBnZAtAQU6kKf"}],"size":8049,"noattachment":false,"key":"/hysnappy/-/hysnappy-1.1.1.tgz"},"_npmUser":{"name":"platypii","email":"platypii@gmail.com"},"directories":{},"maintainers":[{"name":"platypii","email":"platypii@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/hysnappy_1.1.1_1771732580083_0.0715229215399924"},"_hasShrinkwrap":false,"readme":"# HySnappy\n\n![hysnappy penguin](hysnappy.jpg)\n\n[![npm](https://img.shields.io/npm/v/hysnappy)](https://www.npmjs.com/package/hysnappy)\n[![minzipped](https://img.shields.io/bundlephobia/minzip/hysnappy)](https://www.npmjs.com/package/hysnappy)\n[![workflow status](https://github.com/hyparam/hysnappy/actions/workflows/ci.yml/badge.svg)](https://github.com/hyparam/hysnappy/actions)\n[![mit license](https://img.shields.io/badge/License-MIT-orange.svg)](https://opensource.org/licenses/MIT)\n[![dependencies](https://img.shields.io/badge/Dependencies-0-blueviolet)](https://www.npmjs.com/package/hysnappy?activeTab=dependencies)\n\n**HySnappy** is a lightweight, high-performance Snappy compression/decompression library compiled to WebAssembly. It provides:\n- Very fast Snappy compression/decompression suitable for web and Node.js environments.\n- A minimal footprint with no external dependencies.\n- Seamless integration with tools like [Hyparquet](https://github.com/hyparam/hyparquet).\n\n\nThe Snappy compression format, originally released by Google, is designed for high-speed and reasonable compression ratios. HySnappy leverages these strengths by providing a WebAssembly build that can be included directly in your JavaScript bundle for optimal performance.\n\n## Usage\n\n### Decompress Snappy Data\n\nThe `snappyUncompress` function requires arguments:\n - `compressed`: a `Uint8Array` with compressed data.\n - `outputLength`: the uncompressed size of the data.\n\nThe length is needed to know how much wasm memory to allocate.\nFor formats like parquet, this length will generally be known in advance.\n\nTo decompress a `Uint8Array` with known output length:\n\n```javascript\nconst { snappyUncompress } = await import('hysnappy')\n\nconst compressed = new Uint8Array([\n  0x0a, 0x24, 0x68, 0x79, 0x70, 0x65, 0x72, 0x70, 0x61, 0x72, 0x61, 0x6d\n])\nconst outputLength = 10\nconst output = snappyUncompress(compressed, outputLength) // hyperparam\n```\n\n### Compress Snappy Data\n\nUse the `snappyCompress` function to compress a `Uint8Array`:\n\n```javascript\nconst { snappyCompress } = await import('hysnappy')\n\nconst input = new Uint8Array([\n  0x68, 0x79, 0x70, 0x61, 0x72, 0x61, 0x6d\n])\nconst compressed = snappyCompress(input)\n```\n\n## Hyparquet Integration\n\nHysnappy was built specifically to accelerate the [hyparquet](https://github.com/hyparam/hyparquet) parquet parsing library.\n\nHysnappy exports a loader function `snappyUncompressor()` which loads the WASM module once, and returns a pre-loaded version of `snappyUncompress` function.\n\nTo use hysnappy with hyparquet:\n\n```javascript\nimport { parquetQuery } from 'hyparquet'\nimport { snappyUncompressor } from 'hysnappy'\n\nawait parquetQuery({\n  file,\n  compressors: {\n    SNAPPY: snappyUncompressor(),\n  },\n})\n```\n\nAlternatively, check out [hyparquet-compressors](https://github.com/hyparam/hyparquet-compressors) which includes hysnappy decompression.\n\nHysnappy can also be used to accelerate compression in the [hyparquet-writer](https://github.com/hyparam/hyparquet-writer) library (read the [advanced usage section](https://github.com/hyparam/hyparquet-writer#advanced-usage) for details).\n\n## Development\n\nThe build uses clang _without_ emscripten, in order to produce the smallest possible binary.\n\nRun `make` to build from source. The build process consists of:\n\n1. Compile from c to wasm using `clang`.\n2. Encode wasm as base64 to `uncompress.wasm.base64` and `compress.wasm.base64`.\n3. Insert base64 strings into `uncompress.js` and `compress.js` for distribution.\n\n## WASM Loading\n\nBy keeping wasm files under 4kb, we can include it directly in the javascript files and load the WASM blob synchronously, which is faster than loading a separate `.wasm` file. [[web.dev]](https://web.dev/articles/loading-wasm)\n\n## References\n\n - https://en.wikipedia.org/wiki/Snappy_(compression)\n - https://github.com/andikleen/snappy-c\n - https://github.com/google/snappy\n - https://github.com/zhipeng-jia/snappyjs\n - https://web.dev/articles/loading-wasm\n","publish_time":1771732580247,"_cnpm_publish_time":1771732580247,"dist-tags":{"latest":"1.1.1"}}