Comparing version 0.3.0 to 0.3.1
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
export async function snappyUncompress(input: Uint8Array, outputLength: number): Uint8Array | ||
export function snappyUncompress(input: Uint8Array, outputLength: number): Uint8Array | ||
@@ -13,2 +13,2 @@ /** | ||
*/ | ||
export function snappyUncompressor(): (input: Uint8Array, output: number) => Uint8Array | ||
export function snappyUncompressor(): (input: Uint8Array, outputLength: number) => Uint8Array |
{ | ||
"name": "hysnappy", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "snappy decompressor for wasm", | ||
@@ -32,11 +32,11 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/eslint-parser": "7.23.10", | ||
"@types/node": "20.11.21", | ||
"@vitest/coverage-v8": "1.3.1", | ||
"@babel/eslint-parser": "7.24.1", | ||
"@types/node": "20.12.7", | ||
"@vitest/coverage-v8": "1.5.2", | ||
"eslint": "8.57.0", | ||
"eslint-plugin-import": "2.29.1", | ||
"eslint-plugin-jsdoc": "48.2.0", | ||
"eslint-plugin-jsdoc": "48.2.3", | ||
"snappyjs": "0.7.0", | ||
"vitest": "1.3.1" | ||
"vitest": "1.5.2" | ||
} | ||
} |
@@ -12,6 +12,15 @@ # HySnappy | ||
A fast, minimal snappy decompression implementation built for WASM. | ||
A fast, minimal snappy decompression implementation in C built for WASM. | ||
Snappy compression was released by Google in 2011 with the goal of very high speeds and reasonable compression. | ||
Snappy is used in various applications. | ||
For example, snappy is the default compression format for [Apache Parquet](https://parquet.apache.org) files. | ||
## Usage | ||
The `snappyUncompress` function expects as arguments: a typed array `compressed`, and an `outputLength` parameter. | ||
The length is needed to know how much wasm memory to allocate. | ||
For formats like parquet, this length will generally be known in advance. | ||
To decompress a `Uint8Array` with known output length: | ||
```js | ||
@@ -27,9 +36,33 @@ import { snappyUncompress } from 'hysnappy' | ||
## Hyparquet | ||
Hysnappy was built specifically to accelerate the the [hyparquet](https://github.com/hyparam/hyparquet) parquet parsing library. | ||
Hysnappy exports a loader function `snappyUncompressor()` which loads the WASM module once, and returns a pre-loaded version of `snappyUncompress` function. | ||
To use hysnappy with hyparquet: | ||
```js | ||
import { parquetRead } from 'hyparquet' | ||
import { snappyUncompressor } from 'hysnappy' | ||
parquetRead({ file, compressors: { | ||
SNAPPY: snappyUncompressor(), | ||
}}) | ||
``` | ||
## Development | ||
Run `make` to build from source. | ||
The build uses clang _without_ emscripten, in order to produce the smallest possible binary. | ||
Compiles from `snappy.c` to `hysnappy.wasm` using `clang`. | ||
Then encodes `hysnappy.wasm` as base64 to `hysnappy.wasm.base64`, and inserts the base64 string into `hysnappy.js` for distribution. | ||
Run `make` to build from source. The build process consists of: | ||
1. Compile from `snappy.c` to `hysnappy.wasm` using `clang`. | ||
2. Encode `hysnappy.wasm` as base64 to `hysnappy.wasm.base64`. | ||
3. Insert base64 string into `hysnappy.js` for distribution. | ||
## WASM Loading | ||
By keeping `hysnappy.wasm` under 4kb, we can include it directly in the `hysnappy.js` file and load the WASM blob synchronously, which is faster than loading a separate `.wasm` file. [[web.dev]](https://web.dev/articles/loading-wasm) | ||
## References | ||
@@ -41,1 +74,2 @@ | ||
- https://github.com/zhipeng-jia/snappyjs | ||
- https://web.dev/articles/loading-wasm |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12196
73