All Projects → nodeca → Pako

nodeca / Pako

Licence: mit
high speed zlib port to javascript, works in browser & node.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Pako

Libz.jl
Fast, flexible zlib bindings.
Stars: ✭ 26 (-99.32%)
Mutual labels:  zlib
Examples
Smaller or bigger examples that I've written or will write in the future in C++.
Stars: ✭ 14 (-99.63%)
Mutual labels:  zlib
libzip-win-build
libzip Windows build with Visual Studio.
Stars: ✭ 33 (-99.14%)
Mutual labels:  zlib
zzlib
zlib-compressed file depacking library in Lua
Stars: ✭ 44 (-98.85%)
Mutual labels:  zlib
wasm
fast wasm modules
Stars: ✭ 37 (-99.03%)
Mutual labels:  zlib
python-isal
Faster zlib and gzip compatible compression and decompression by providing python bindings for the isa-l library.
Stars: ✭ 21 (-99.45%)
Mutual labels:  zlib
ZipArchive
A single-class pure VB6 library for zip with ASM speed
Stars: ✭ 38 (-99.01%)
Mutual labels:  zlib
decompress
Pure OCaml implementation of Zlib.
Stars: ✭ 103 (-97.31%)
Mutual labels:  zlib
zlib
Compression and decompression in the gzip and zlib formats
Stars: ✭ 32 (-99.16%)
Mutual labels:  zlib
DolphinDBPlugin
No description or website provided.
Stars: ✭ 33 (-99.14%)
Mutual labels:  zlib
power-gzip
POWER9 gzip engine documentation and code samples
Stars: ✭ 16 (-99.58%)
Mutual labels:  zlib
zlib-win-build
zlib Windows build with Visual Studio.
Stars: ✭ 100 (-97.39%)
Mutual labels:  zlib
kobopatch-patches
Patches for use with kobopatch.
Stars: ✭ 134 (-96.5%)
Mutual labels:  zlib
libz-sys
Rust crate package to link to a system libz (zlib)
Stars: ✭ 70 (-98.17%)
Mutual labels:  zlib
tbag
Tea-bag is Third party extension utility project
Stars: ✭ 13 (-99.66%)
Mutual labels:  zlib
mtscomp
Multichannel time series lossless compression in pure Python based on NumPy and zlib
Stars: ✭ 20 (-99.48%)
Mutual labels:  zlib
deflate-rs
An implementation of a DEFLATE encoder in rust
Stars: ✭ 47 (-98.77%)
Mutual labels:  zlib
Zipper
C++ wrapper around minizip compression library
Stars: ✭ 272 (-92.9%)
Mutual labels:  zlib
lzbase62
LZ77(LZSS) based compression algorithm in base62 for JavaScript.
Stars: ✭ 38 (-99.01%)
Mutual labels:  zlib
zopflipy
A Python bindings for Zopfli
Stars: ✭ 17 (-99.56%)
Mutual labels:  zlib

pako

CI NPM version

zlib port to javascript, very fast!

Why pako is cool:

  • Results are binary equal to well known zlib (now contains ported zlib v1.2.8).
  • Almost as fast in modern JS engines as C implementation (see benchmarks).
  • Works in browsers, you can browserify any separate component.

This project was done to understand how fast JS can be and is it necessary to develop native C modules for CPU-intensive tasks. Enjoy the result!

Benchmarks:

node v12.16.3 (zlib 1.2.9), 1mb input sample:

deflate-imaya x 4.75 ops/sec ±4.93% (15 runs sampled)
deflate-pako x 10.38 ops/sec ±0.37% (29 runs sampled)
deflate-zlib x 17.74 ops/sec ±0.77% (46 runs sampled)
gzip-pako x 8.86 ops/sec ±1.41% (29 runs sampled)
inflate-imaya x 107 ops/sec ±0.69% (77 runs sampled)
inflate-pako x 131 ops/sec ±1.74% (82 runs sampled)
inflate-zlib x 258 ops/sec ±0.66% (88 runs sampled)
ungzip-pako x 115 ops/sec ±1.92% (80 runs sampled)

node v14.15.0 (google's zlib), 1mb output sample:

deflate-imaya x 4.93 ops/sec ±3.09% (16 runs sampled)
deflate-pako x 10.22 ops/sec ±0.33% (29 runs sampled)
deflate-zlib x 18.48 ops/sec ±0.24% (48 runs sampled)
gzip-pako x 10.16 ops/sec ±0.25% (28 runs sampled)
inflate-imaya x 110 ops/sec ±0.41% (77 runs sampled)
inflate-pako x 134 ops/sec ±0.66% (83 runs sampled)
inflate-zlib x 402 ops/sec ±0.74% (87 runs sampled)
ungzip-pako x 113 ops/sec ±0.62% (80 runs sampled)

zlib's test is partially affected by marshalling (that make sense for inflate only). You can change deflate level to 0 in benchmark source, to investigate details. For deflate level 6 results can be considered as correct.

Install:

npm install pako

Examples / API

Full docs - http://nodeca.github.io/pako/

const pako = require('pako');

// Deflate
//
const input = new Uint8Array();
//... fill input data here
const output = pako.deflate(input);

// Inflate (simple wrapper can throw exception on broken stream)
//
const compressed = new Uint8Array();
//... fill data to uncompress here
try {
  const result = pako.inflate(compressed);
  // ... continue processing
} catch (err) {
  console.log(err);
}

//
// Alternate interface for chunking & without exceptions
//

const deflator = new pako.Deflate();

deflator.push(chunk1, false);
deflator.push(chunk2); // second param is false by default.
...
deflator.push(chunk_last, true); // `true` says this chunk is last

if (deflator.err) {
  console.log(deflator.msg);
}

const output = deflator.result;


const inflator = new pako.Inflate();

inflator.push(chunk1);
inflator.push(chunk2);
...
inflator.push(chunk_last); // no second param because end is auto-detected

if (inflator.err) {
  console.log(inflator.msg);
}

const output = inflator.result;

Sometime you can wish to work with strings. For example, to send stringified objects to server. Pako's deflate detects input data type, and automatically recode strings to utf-8 prior to compress. Inflate has special option, to say compressed data has utf-8 encoding and should be recoded to javascript's utf-16.

const pako = require('pako');

const test = { my: 'super', puper: [456, 567], awesome: 'pako' };

const compressed = pako.deflate(JSON.stringify(test));

const restored = JSON.parse(pako.inflate(compressed, { to: 'string' }));

Notes

Pako does not contain some specific zlib functions:

  • deflate - methods deflateCopy, deflateBound, deflateParams, deflatePending, deflatePrime, deflateTune.
  • inflate - methods inflateCopy, inflateMark, inflatePrime, inflateGetDictionary, inflateSync, inflateSyncPoint, inflateUndermine.
  • High level inflate/deflate wrappers (classes) may not support some flush modes.

pako for enterprise

Available as part of the Tidelift Subscription

The maintainers of pako and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Authors

Personal thanks to:

  • Vyacheslav Egorov (@mraleph) for his awesome tutorials about optimising JS code for v8, IRHydra tool and his advices.
  • David Duponchel (@dduponchel) for help with testing.

Original implementation (in C):

  • zlib by Jean-loup Gailly and Mark Adler.

License

  • MIT - all files, except /lib/zlib folder
  • ZLIB - /lib/zlib content
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].