pako - zlib port to javascript, very fast!
 
 
 
Go to file
Vitaly Puzrin dfe21c62da docs update 2014-03-12 05:01:30 +04:00
benchmark
dist
lib
test
.gitignore
.jshintignore
.jshintrc
.ndocrc
.npmignore
.travis.yml
Gruntfile.js
LICENSE
Makefile
README.md
bower.json
index.js
package.json

README.md

pako - zlib port to javascript, very fast!

Build Status

Why pako is cool:

  • Almost as fast in modern JS engines as C implementation (see benchmarks).
  • Works in browsers, you can browserify any separate component.
  • Both Sync & streamable (for big blobs) interfaces.
  • It's fresh - ports the latest zlib version (now 1.2.8), results are binary equal.

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 v0.10, 10mb sample:

   deflate-gildas x 4.62 ops/sec ±1.93% (15 runs sampled)
   deflate-imaya x 3.82 ops/sec ±1.31% (13 runs sampled)
 ! deflate-pako x 9.09 ops/sec ±0.42% (26 runs sampled)
   deflate-zlib x 14.16 ops/sec ±3.33% (63 runs sampled)

node v0.11, 10mb sample:

   deflate-gildas x 5.10 ops/sec ±4.94% (16 runs sampled)
   deflate-imaya x 3.42 ops/sec ±4.11% (12 runs sampled)
 ! deflate-pako x 11.28 ops/sec ±0.42% (32 runs sampled)
   deflate-zlib x 14.17 ops/sec ±3.34% (64 runs sampled)

If you doubt, that zlib is slow because of marshalling, try benchmark with level 0. You will see, that node bindings don't add noticeable slowdown.

Install:

node.js:

npm install pako

browser:

bower install pako

Example & API

Full docs.

var pako = require('pako');

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

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

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

var inflator = new pako.Inflate();

inflator.push(chunk1, false);
inflator.push(chunk2, false);
...
inflator.push(chunkN, true); // true -> last

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

var output = inflator.result;

Notes

Pako does not contains some very specific zlib functions.

  • deflate - writing bustom gzip headers and methods deflateSetDictionary, deflateParams, deflateSetHeader, deflateBound, deflatePending.
  • inflate - TBD.

Authors

Personal thanks to Vyacheslav Egorov (@mraleph) for his awesome tutoruals about optimising JS code for v8, IRHydra tool and his advices.

License

MIT