Debian Codegraph @

resources/lib/pako/README.md

raw symbols SCIP
1 pako
2 ==========================================
3
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)
6
7 > zlib port to javascript, very fast!
8
9 __Why pako is cool:__
10
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.
14
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!
17
18
19 __Benchmarks:__
20
21
22 node v12.16.3 (zlib 1.2.9), 1mb input sample:
23
24 ```
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)
33 ```
34
35 node v14.15.0 (google's zlib), 1mb output sample:
36
37 ```
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)
46 ```
47
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.
51
52 __Install:__
53
54 ```
55 npm install pako
56 ```
57
58
59 Examples / API
60 --------------
61
62 Full docs - http://nodeca.github.io/pako/
63
64 ```javascript
65 const pako = require('pako');
66
67 // Deflate
68 //
69 const input = new Uint8Array();
70 //... fill input data here
71 const output = pako.deflate(input);
72
73 // Inflate (simple wrapper can throw exception on broken stream)
74 //
75 const compressed = new Uint8Array();
76 //... fill data to uncompress here
77 try {
78 const result = pako.inflate(compressed);
79 // ... continue processing
80 } catch (err) {
81 console.log(err);
82 }
83
84 //
85 // Alternate interface for chunking & without exceptions
86 //
87
88 const deflator = new pako.Deflate();
89
90 deflator.push(chunk1, false);
91 deflator.push(chunk2); // second param is false by default.
92 ...
93 deflator.push(chunk_last, true); // `true` says this chunk is last
94
95 if (deflator.err) {
96 console.log(deflator.msg);
97 }
98
99 const output = deflator.result;
100
101
102 const inflator = new pako.Inflate();
103
104 inflator.push(chunk1);
105 inflator.push(chunk2);
106 ...
107 inflator.push(chunk_last); // no second param because end is auto-detected
108
109 if (inflator.err) {
110 console.log(inflator.msg);
111 }
112
113 const output = inflator.result;
114 ```
115
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
120 javascript's utf-16.
121
122 ```javascript
123 const pako = require('pako');
124
125 const test = { my: 'super', puper: [456, 567], awesome: 'pako' };
126
127 const compressed = pako.deflate(JSON.stringify(test));
128
129 const restored = JSON.parse(pako.inflate(compressed, { to: 'string' }));
130 ```
131
132
133 Notes
134 -----
135
136 Pako does not contain some specific zlib functions:
137
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
143 modes.
144
145
146 pako for enterprise
147 -------------------
148
149 Available as part of the Tidelift Subscription
150
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)
152
153
154 Authors
155 -------
156
157 - Andrey Tupitsin [@anrd83](https://github.com/andr83)
158 - Vitaly Puzrin [@puzrin](https://github.com/puzrin)
159
160 Personal thanks to:
161
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
166 testing.
167
168 Original implementation (in C):
169
170 - [zlib](http://zlib.net/) by Jean-loup Gailly and Mark Adler.
171
172
173 License
174 -------
175
176 - MIT - all files, except `/lib/zlib` folder
177 - ZLIB - `/lib/zlib` content