The fastest compression and decompression in the browser.
npm i wasm-flate
wapm install drbh/flate
Or use it in you HTML page with the precompiled CDN version
For server side code
check out the examples for code to decompress data in Python, Node and Go on the server side
Docs - get API reference and flate functions.
Examples - Examples compressing in browser, sending to node server and decompressing... really fast!
Compared to JS implementation (pako)
wasm-flate in your browsers here
In Chrome on my MacBook Pro, we see that pako takes about 143 ms where
wasm-flate only takes about 21 ms. This is 6.8x faster.
WASM npm library for fast (de)compression
- Uses WASM
- As fast as C or Rust implementation
- Works in all browsers
- GZIP supported
- ZLIB supported
- DELFATE supported
- Shipping compressed data from server and decompress in browser
- Shipping compressed data to server by compressing in browser
- Better UX for mobile (fast decompress - slow data fetch)
- Better UX for people with sparse networks
- Less resource use on server side
- Decreased storage need
- Leveraging growing WASM ecosystem
This package allows you to quickly compress and decompress data in the browser. The process is simple and optmized to execute as fast as your browser can run.
Pass a string or Uint8Array to the compression function you choose. The contents will be compressed and encoded to base64. The returned value will be a base64 encoded string.
Pass a base64 string of the compressed data and it will return a base64 decompressed value.
Example Node use
var flate = ;var data = "THIS IS EXAMPLE DATA TO COMPRESS"var compressed_data = flatevar original_data = flate
Full Use Example
This will read in the string as a u8array, compress, decompress and compare the output with the original value. This show cases all the main uses of
var flate = ;var data = Buffer ;var comp = flatevar decomp = flateJSON === JSON
Here we can see how to compress data as a string, and it will return a base64 encoded compressed value.
var data = "THIS IS EXAMPLE DATA TO COMPRESS"var compressed_data = flate// this data is zlib compressed and base64 encoded
var data = "THIS IS EXAMPLE DATA TO COMPRESS"var compressed_data = flate// this data is gzip compressed and base64 encoded
var data = "THIS IS EXAMPLE DATA TO COMPRESS"var compressed_data = flate// this data is deflate compressed and base64 encoded
var original_data = flate
The folowing output is some compressed JSON of ECR20 tokens traded on a DEX (the data used is arbitrary!)
- Compile compression to WASM
- Build useful functions for compression
- Compile useful functions to WASM
- Publish NPM package of WASM files and JS shim
- Add new functions for u8Array support
- Add basic API docs
- Write short medium article
- Compare with Native JS example
- Add node server side example
- Add Python server side example
- Make logo for lib based on WASM colorway
- Deploy to WAPM
- Add Golang example
- Add benchmarking suite
- Deploy multi file example
- Release solid roadmap
- Releae update schedule
- Find partner for case study
Building with Rust 🦀🕸️
In order to build the wasm files with Rust, you'll need to clone the repo and run
nodejs as the target. This will create a set of files in
pkg that can be used as a node module.
git clone https://github.com/drbh/wasm-flate.git cd wasm-flate wasm-pack build --target nodejs
You should have the following new files
pkg/ ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── wasm-flate.d.ts ├── wasm-flate.js ├── wasm-flate_bg.d.ts ├── wasm-flate_bg.js ├── wasm-flate_bg.wasm └── package.json
If you found
wasm-flate useful feel free to buy me a beer 🍺 or two 😀
BTC - 3QVK6D5QCZDSyLzFL3ZbELokyuSprRQQZF