1
pako - zlib port to javascript, very fast!
2
==========================================
4
[![Build Status](https://travis-ci.org/nodeca/pako.svg?branch=master)](https://travis-ci.org/nodeca/pako)
5
[![NPM version](https://img.shields.io/npm/v/pako.svg)](https://www.npmjs.org/package/pako)
9
- Almost as fast in modern JS engines as C implementation (see benchmarks).
10
- Works in browsers, you can browserify any separate component.
11
- Chunking support for big blobs.
12
- Results are binary equal to well known [zlib](http://www.zlib.net/) (now v1.2.8 ported).
14
This project was done to understand how fast JS can be and is it necessary to
15
develop native C modules for CPU-intensive tasks. Enjoy the result!
18
__Famous projects, using pako:__
20
- [browserify](http://browserify.org/) (via [browserify-zlib](https://github.com/devongovett/browserify-zlib))
21
- [JSZip](http://stuk.github.io/jszip/)
22
- [mincer](https://github.com/nodeca/mincer)
23
- [JS-Git](https://github.com/creationix/js-git) and
24
[Tedit](https://chrome.google.com/webstore/detail/tedit-development-environ/ooekdijbnbbjdfjocaiflnjgoohnblgf)
25
by [@creatronix](https://github.com/creationix)
31
node v0.10.26, 1mb sample:
33
deflate-dankogai x 4.73 ops/sec ±0.82% (15 runs sampled)
34
deflate-gildas x 4.58 ops/sec ±2.33% (15 runs sampled)
35
deflate-imaya x 3.22 ops/sec ±3.95% (12 runs sampled)
36
! deflate-pako x 6.99 ops/sec ±0.51% (21 runs sampled)
37
deflate-pako-string x 5.89 ops/sec ±0.77% (18 runs sampled)
38
deflate-pako-untyped x 4.39 ops/sec ±1.58% (14 runs sampled)
39
* deflate-zlib x 14.71 ops/sec ±4.23% (59 runs sampled)
40
inflate-dankogai x 32.16 ops/sec ±0.13% (56 runs sampled)
41
inflate-imaya x 30.35 ops/sec ±0.92% (53 runs sampled)
42
! inflate-pako x 69.89 ops/sec ±1.46% (71 runs sampled)
43
inflate-pako-string x 19.22 ops/sec ±1.86% (49 runs sampled)
44
inflate-pako-untyped x 17.19 ops/sec ±0.85% (32 runs sampled)
45
* inflate-zlib x 70.03 ops/sec ±1.64% (81 runs sampled)
47
node v0.11.12, 1mb sample:
49
deflate-dankogai x 5.60 ops/sec ±0.49% (17 runs sampled)
50
deflate-gildas x 5.06 ops/sec ±6.00% (16 runs sampled)
51
deflate-imaya x 3.52 ops/sec ±3.71% (13 runs sampled)
52
! deflate-pako x 11.52 ops/sec ±0.22% (32 runs sampled)
53
deflate-pako-string x 9.53 ops/sec ±1.12% (27 runs sampled)
54
deflate-pako-untyped x 5.44 ops/sec ±0.72% (17 runs sampled)
55
* deflate-zlib x 14.05 ops/sec ±3.34% (63 runs sampled)
56
inflate-dankogai x 42.19 ops/sec ±0.09% (56 runs sampled)
57
inflate-imaya x 79.68 ops/sec ±1.07% (68 runs sampled)
58
! inflate-pako x 97.52 ops/sec ±0.83% (80 runs sampled)
59
inflate-pako-string x 45.19 ops/sec ±1.69% (57 runs sampled)
60
inflate-pako-untyped x 24.35 ops/sec ±2.59% (40 runs sampled)
61
* inflate-zlib x 60.32 ops/sec ±1.36% (69 runs sampled)
64
zlib's test is partialy afferted by marshling (that make sense for inflate only).
65
You can change deflate level to 0 in benchmark source, to investigate details.
66
For deflate level 6 results can be considered as correct.
86
Full docs - http://nodeca.github.io/pako/
89
var pako = require('pako');
93
var input = new Uint8Array();
94
//... fill input data here
95
var output = pako.deflate(input);
97
// Inflate (simple wrapper can throw exception on broken stream)
99
var compressed = new Uint8Array();
100
//... fill data to uncompress here
102
var result = pako.inflate(compressed);
108
// Alternate interface for chunking & without exceptions
111
var inflator = new pako.Inflate();
113
inflator.push(chunk1, false);
114
inflator.push(chunk2, false);
116
inflator.push(chunkN, true); // true -> last chunk
119
console.log(inflator.msg);
122
var output = inflator.result;
126
Sometime you can wish to work with strings. For example, to send
127
big objects as json to server. Pako detects input data type. You can
128
force output to be string with option `{ to: 'string' }`.
131
var pako = require('pako');
133
var test = { my: 'super', puper: [456, 567], awesome: 'pako' };
135
var binaryString = pako.deflate(JSON.stringify(test), { to: 'string' });
138
// Here you can do base64 encode, make xhr requests and so on.
141
var restored = JSON.parse(pako.inflate(binaryString, { to: 'string' }));
148
Pako does not contain some specific zlib functions:
150
- __deflate__ - methods `deflateCopy`, `deflateBound`, `deflateParams`,
151
`deflatePending`, `deflatePrime`, `deflateSetDictionary`, `deflateTune`.
152
- __inflate__ - `inflateGetDictionary`, `inflateCopy`, `inflateMark`,
153
`inflatePrime`, `inflateSetDictionary`, `inflateSync`, `inflateSyncPoint`,
160
- Andrey Tupitsin [@anrd83](https://github.com/andr83)
161
- Vitaly Puzrin [@puzrin](https://github.com/puzrin)
165
- Vyacheslav Egorov ([@mraleph](https://github.com/mraleph)) for his awesome
166
tutorials about optimising JS code for v8, [IRHydra](http://mrale.ph/irhydra/)
167
tool and his advices.
168
- David Duponchel ([@dduponchel](https://github.com/dduponchel)) for help with