~holger-seelig/cobweb.js/trunk

« back to all changes in this revision

Viewing changes to src/lib/pako/README.md

  • Committer: Holger Seelig
  • Date: 2017-08-22 04:53:24 UTC
  • Revision ID: holger.seelig@yahoo.de-20170822045324-4of4xxgt79669gbt
Switched to npm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
pako - zlib port to javascript, very fast!
 
2
==========================================
 
3
 
 
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)
 
6
 
 
7
__Why pako is cool:__
 
8
 
 
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).
 
13
 
 
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!
 
16
 
 
17
 
 
18
__Famous projects, using pako:__
 
19
 
 
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)
 
26
 
 
27
 
 
28
__Benchmarks:__
 
29
 
 
30
```
 
31
node v0.10.26, 1mb sample:
 
32
 
 
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)
 
46
 
 
47
node v0.11.12, 1mb sample:
 
48
 
 
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)
 
62
```
 
63
 
 
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.
 
67
 
 
68
__Install:__
 
69
 
 
70
node.js:
 
71
 
 
72
```
 
73
npm install pako
 
74
```
 
75
 
 
76
browser:
 
77
 
 
78
```
 
79
bower install pako
 
80
```
 
81
 
 
82
 
 
83
Example & API
 
84
-------------
 
85
 
 
86
Full docs - http://nodeca.github.io/pako/
 
87
 
 
88
```javascript
 
89
var pako = require('pako');
 
90
 
 
91
// Deflate
 
92
//
 
93
var input = new Uint8Array();
 
94
//... fill input data here
 
95
var output = pako.deflate(input);
 
96
 
 
97
// Inflate (simple wrapper can throw exception on broken stream)
 
98
//
 
99
var compressed = new Uint8Array();
 
100
//... fill data to uncompress here
 
101
try {
 
102
  var result = pako.inflate(compressed);
 
103
} catch (err) {
 
104
  console.log(err);
 
105
}
 
106
 
 
107
//
 
108
// Alternate interface for chunking & without exceptions
 
109
//
 
110
 
 
111
var inflator = new pako.Inflate();
 
112
 
 
113
inflator.push(chunk1, false);
 
114
inflator.push(chunk2, false);
 
115
...
 
116
inflator.push(chunkN, true); // true -> last chunk
 
117
 
 
118
if (inflator.err) {
 
119
  console.log(inflator.msg);
 
120
}
 
121
 
 
122
var output = inflator.result;
 
123
 
 
124
```
 
125
 
 
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' }`.
 
129
 
 
130
```javascript
 
131
var pako = require('pako');
 
132
 
 
133
var test = { my: 'super', puper: [456, 567], awesome: 'pako' };
 
134
 
 
135
var binaryString = pako.deflate(JSON.stringify(test), { to: 'string' });
 
136
 
 
137
//
 
138
// Here you can do base64 encode, make xhr requests and so on.
 
139
//
 
140
 
 
141
var restored = JSON.parse(pako.inflate(binaryString, { to: 'string' }));
 
142
```
 
143
 
 
144
 
 
145
Notes
 
146
-----
 
147
 
 
148
Pako does not contain some specific zlib functions:
 
149
 
 
150
- __deflate__ -  methods `deflateCopy`, `deflateBound`, `deflateParams`,
 
151
  `deflatePending`, `deflatePrime`, `deflateSetDictionary`, `deflateTune`.
 
152
- __inflate__ - `inflateGetDictionary`, `inflateCopy`, `inflateMark`,
 
153
  `inflatePrime`, `inflateSetDictionary`, `inflateSync`, `inflateSyncPoint`,
 
154
  `inflateUndermine`.
 
155
 
 
156
 
 
157
Authors
 
158
-------
 
159
 
 
160
- Andrey Tupitsin [@anrd83](https://github.com/andr83)
 
161
- Vitaly Puzrin [@puzrin](https://github.com/puzrin)
 
162
 
 
163
Personal thanks to:
 
164
 
 
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
 
169
  testing.
 
170
 
 
171
 
 
172
License
 
173
-------
 
174
 
 
175
MIT