{"name":"hysnappy","version":"0.1.2","keywords":["snappy","compression","compress","decompress","decompression","wasm","webassembly"],"license":"MIT","_id":"hysnappy@0.1.2","maintainers":[{"name":"platypii","email":"platypii@gmail.com"}],"homepage":"https://github.com/hyparam/hysnappy#readme","bugs":{"url":"https://github.com/hyparam/hysnappy/issues"},"dist":{"shasum":"388b363bdfffaa7a9f9222bc5380c3d004216044","tarball":"http://registry-npm.ywwl.com/hysnappy/download/hysnappy-0.1.2.tgz","fileCount":5,"integrity":"sha512-bNzx45e5IZy/xYXDGmID2TQJ64VjlTpZhEzpibrPFdZxiMKup9n9IbjMFfywCvozKn5QD/UI77r/gfBiskZWTA==","signatures":[{"sig":"MEYCIQC9LhUv1B/9lDTWT7MRG/TOAg24PCKZu/gNVph4B9eUgAIhAKFOVWj368cKk67Rk1rub5sQHqAphnbMmLz+0AKMXWxV","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10640,"size":5364,"noattachment":false,"key":"/hysnappy/-/hysnappy-0.1.2.tgz"},"main":"hysnappy.js","type":"module","types":"hysnappy.d.ts","gitHead":"dbfb45e39675d20a06a6d965ebf110cf2b75de24","scripts":{"lint":"eslint .","test":"vitest run","coverage":"vitest run --coverage"},"_npmUser":{"name":"platypii","email":"platypii@gmail.com"},"repository":{"url":"git+https://github.com/hyparam/hysnappy.git","type":"git"},"_npmVersion":"10.2.4","description":"snappy decompressor for wasm","directories":{},"_nodeVersion":"21.6.2","_hasShrinkwrap":false,"devDependencies":{"eslint":"8.56.0","vitest":"1.3.1","snappyjs":"0.7.0","@types/node":"20.11.19","@vitest/coverage-v8":"1.3.1","eslint-plugin-jsdoc":"48.1.0","@babel/eslint-parser":"7.23.10","eslint-plugin-import":"2.29.1"},"_npmOperationalInternal":{"tmp":"tmp/hysnappy_0.1.2_1708552967483_0.8400712127127672","host":"s3://npm-registry-packages"},"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":1708552967708,"_cnpm_publish_time":1708552967708,"dist-tags":{"latest":"1.1.1"}}