2 ==========================================
4 [![CI](https://github.com/nodeca/pako/workflows/CI/badge.svg)](https://github.com/nodeca/pako/actions)
5 [![NPM version](https://img.shields.io/npm/v/pako.svg)](https://www.npmjs.org/package/pako)
7 > zlib port to javascript, very fast!
11 - Results are binary equal to well known [zlib](http://www.zlib.net/) (now contains ported zlib v1.2.8).
12 - Almost as fast in modern JS engines as C implementation (see benchmarks).
13 - Works in browsers, you can browserify any separate component.
15 This project was done to understand how fast JS can be and is it necessary to
16 develop native C modules for CPU-intensive tasks. Enjoy the result!
22 node v12.16.3 (zlib 1.2.9), 1mb input sample:
25 deflate-imaya x 4.75 ops/sec ±4.93% (15 runs sampled)
26 deflate-pako x 10.38 ops/sec ±0.37% (29 runs sampled)
27 deflate-zlib x 17.74 ops/sec ±0.77% (46 runs sampled)
28 gzip-pako x 8.86 ops/sec ±1.41% (29 runs sampled)
29 inflate-imaya x 107 ops/sec ±0.69% (77 runs sampled)
30 inflate-pako x 131 ops/sec ±1.74% (82 runs sampled)
31 inflate-zlib x 258 ops/sec ±0.66% (88 runs sampled)
32 ungzip-pako x 115 ops/sec ±1.92% (80 runs sampled)
35 node v14.15.0 (google's zlib), 1mb output sample:
38 deflate-imaya x 4.93 ops/sec ±3.09% (16 runs sampled)
39 deflate-pako x 10.22 ops/sec ±0.33% (29 runs sampled)
40 deflate-zlib x 18.48 ops/sec ±0.24% (48 runs sampled)
41 gzip-pako x 10.16 ops/sec ±0.25% (28 runs sampled)
42 inflate-imaya x 110 ops/sec ±0.41% (77 runs sampled)
43 inflate-pako x 134 ops/sec ±0.66% (83 runs sampled)
44 inflate-zlib x 402 ops/sec ±0.74% (87 runs sampled)
45 ungzip-pako x 113 ops/sec ±0.62% (80 runs sampled)
48 zlib's test is partially affected by marshalling (that make sense for inflate only).
49 You can change deflate level to 0 in benchmark source, to investigate details.
50 For deflate level 6 results can be considered as correct.
62 Full docs - http://nodeca.github.io/pako/
65 const pako = require('pako');
69 const input = new Uint8Array();
70 //... fill input data here
71 const output = pako.deflate(input);
73 // Inflate (simple wrapper can throw exception on broken stream)
75 const compressed = new Uint8Array();
76 //... fill data to uncompress here
78 const result = pako.inflate(compressed);
79 // ... continue processing
85 // Alternate interface for chunking & without exceptions
88 const deflator = new pako.Deflate();
90 deflator.push(chunk1, false);
91 deflator.push(chunk2); // second param is false by default.
93 deflator.push(chunk_last, true); // `true` says this chunk is last
96 console.log(deflator.msg);
99 const output = deflator.result;
102 const inflator = new pako.Inflate();
104 inflator.push(chunk1);
105 inflator.push(chunk2);
107 inflator.push(chunk_last); // no second param because end is auto-detected
110 console.log(inflator.msg);
113 const output = inflator.result;
116 Sometime you can wish to work with strings. For example, to send
117 stringified objects to server. Pako's deflate detects input data type, and
118 automatically recode strings to utf-8 prior to compress. Inflate has special
119 option, to say compressed data has utf-8 encoding and should be recoded to
123 const pako = require('pako');
125 const test = { my: 'super', puper: [456, 567], awesome: 'pako' };
127 const compressed = pako.deflate(JSON.stringify(test));
129 const restored = JSON.parse(pako.inflate(compressed, { to: 'string' }));
136 Pako does not contain some specific zlib functions:
138 - __deflate__ - methods `deflateCopy`, `deflateBound`, `deflateParams`,
139 `deflatePending`, `deflatePrime`, `deflateTune`.
140 - __inflate__ - methods `inflateCopy`, `inflateMark`,
141 `inflatePrime`, `inflateGetDictionary`, `inflateSync`, `inflateSyncPoint`, `inflateUndermine`.
142 - High level inflate/deflate wrappers (classes) may not support some flush
149 Available as part of the Tidelift Subscription
151 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.](https://tidelift.com/subscription/pkg/npm-pako?utm_source=npm-pako&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
157 - Andrey Tupitsin [@anrd83](https://github.com/andr83)
158 - Vitaly Puzrin [@puzrin](https://github.com/puzrin)
162 - Vyacheslav Egorov ([@mraleph](https://github.com/mraleph)) for his awesome
163 tutorials about optimising JS code for v8, [IRHydra](http://mrale.ph/irhydra/)
164 tool and his advices.
165 - David Duponchel ([@dduponchel](https://github.com/dduponchel)) for help with
168 Original implementation (in C):
170 - [zlib](http://zlib.net/) by Jean-loup Gailly and Mark Adler.
176 - MIT - all files, except `/lib/zlib` folder
177 - ZLIB - `/lib/zlib` content