pako - zlib port to javascript, very fast!
 
 
 
Go to file
Vitaly Puzrin 165bfe934c browserified files rebuild 2014-05-01 22:14:33 +04:00
benchmark Final utf8 decoder opt (2-3x speed boost) 2014-04-15 06:43:23 +04:00
dist browserified files rebuild 2014-05-01 22:14:33 +04:00
lib remove codes table variable & add switching between fixed and dynamic tables for inflate, issue #22 2014-05-01 14:51:44 -03:00
test remove codes table variable & add switching between fixed and dynamic tables for inflate, issue #22 2014-05-01 14:51:44 -03:00
.gitignore Added tests to run in browser (no CI yet) 2014-02-27 21:58:12 +04:00
.jshintignore Added tests to run in browser (no CI yet) 2014-02-27 21:58:12 +04:00
.jshintrc implement deflate store + high level deflate implementation + lint fixes 2014-02-13 14:55:24 -02:00
.ndocrc Added generated API docs 2014-02-20 01:38:10 +04:00
.npmignore updated ignore masks 2014-02-24 06:17:00 +04:00
.travis.yml Saucelabs config update 2014-04-09 22:45:15 +04:00
Gruntfile.js Saucelabs config update 2014-04-09 22:45:15 +04:00
HISTORY.md 0.2.1 release 2014-05-01 22:13:30 +04:00
LICENSE readme & license 2014-02-18 21:55:32 +04:00
Makefile Increased tests timeout (needed for CI) 2014-03-13 00:41:05 +04:00
README.md docs/comments update 2014-04-18 02:56:41 +04:00
bower.json browserified files rebuild 2014-05-01 22:14:33 +04:00
index.js Moved utilities to separate folder 2014-04-13 13:45:12 +04:00
package.json 0.2.1 release 2014-05-01 22:13:30 +04:00

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.
  • Chunking support for big blobs.
  • Results are binary equal to well known zlib (now v1.2.8 ported).

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!

Famous projects, using pako:

Benchmarks:

node v0.10.26, 1mb sample:

   deflate-dankogai x 4.73 ops/sec ±0.82% (15 runs sampled)
   deflate-gildas x 4.58 ops/sec ±2.33% (15 runs sampled)
   deflate-imaya x 3.22 ops/sec ±3.95% (12 runs sampled)
 ! deflate-pako x 6.99 ops/sec ±0.51% (21 runs sampled)
   deflate-pako-string x 5.89 ops/sec ±0.77% (18 runs sampled)
   deflate-pako-untyped x 4.39 ops/sec ±1.58% (14 runs sampled)
 * deflate-zlib x 14.71 ops/sec ±4.23% (59 runs sampled)
   inflate-dankogai x 32.16 ops/sec ±0.13% (56 runs sampled)
   inflate-imaya x 30.35 ops/sec ±0.92% (53 runs sampled)
 ! inflate-pako x 69.89 ops/sec ±1.46% (71 runs sampled)
   inflate-pako-string x 19.22 ops/sec ±1.86% (49 runs sampled)
   inflate-pako-untyped x 17.19 ops/sec ±0.85% (32 runs sampled)
 * inflate-zlib x 70.03 ops/sec ±1.64% (81 runs sampled)

node v0.11.12, 1mb sample:

   deflate-dankogai x 5.60 ops/sec ±0.49% (17 runs sampled)
   deflate-gildas x 5.06 ops/sec ±6.00% (16 runs sampled)
   deflate-imaya x 3.52 ops/sec ±3.71% (13 runs sampled)
 ! deflate-pako x 11.52 ops/sec ±0.22% (32 runs sampled)
   deflate-pako-string x 9.53 ops/sec ±1.12% (27 runs sampled)
   deflate-pako-untyped x 5.44 ops/sec ±0.72% (17 runs sampled)
 * deflate-zlib x 14.05 ops/sec ±3.34% (63 runs sampled)
   inflate-dankogai x 42.19 ops/sec ±0.09% (56 runs sampled)
   inflate-imaya x 79.68 ops/sec ±1.07% (68 runs sampled)
 ! inflate-pako x 97.52 ops/sec ±0.83% (80 runs sampled)
   inflate-pako-string x 45.19 ops/sec ±1.69% (57 runs sampled)
   inflate-pako-untyped x 24.35 ops/sec ±2.59% (40 runs sampled)
 * inflate-zlib x 60.32 ops/sec ±1.36% (69 runs sampled)

zlib's test is partialy afferted by marshling (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:

node.js:

npm install pako

browser:

bower install pako

Example & API

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

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 chunk

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

var output = inflator.result;

Sometime you can wish to work with strings. For example, to send big objects as json to server. Pako detects input data type. You can force output to be string with option { to: 'string' }.

var pako = require('pako');

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

var binaryString = pako.deflate(JSON.stringify(test), { to: 'string' });

//
// Here you can do base64 encode, make xhr requests and so on.
//

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

Notes

Pako does not contain some specific zlib functions:

  • deflate - methods deflateCopy, deflateBound, deflateParams, deflatePending, deflatePrime, deflateSetDictionary, deflateTune.
  • inflate - inflateGetDictionary, inflateCopy, inflateMark, inflatePrime, inflateSetDictionary, inflateSync, inflateSyncPoint, inflateUndermine.

Authors

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

License

MIT