Pinsave/counterstrike
1
1pako2==========================================3 4[](https://travis-ci.org/nodeca/pako)5[](https://www.npmjs.org/package/pako)6 7> zlib port to javascript, very fast!8 9__Why pako is cool:__10 11- Almost as fast in modern JS engines as C implementation (see benchmarks).12- Works in browsers, you can browserify any separate component.13- Chunking support for big blobs.14- Results are binary equal to well known [zlib](http://www.zlib.net/) (now contains ported zlib v1.2.8).15 16This project was done to understand how fast JS can be and is it necessary to17develop native C modules for CPU-intensive tasks. Enjoy the result!18 19 20__Famous projects, using pako:__21 22- [browserify](http://browserify.org/) (via [browserify-zlib](https://github.com/devongovett/browserify-zlib))23- [JSZip](http://stuk.github.io/jszip/)24- [mincer](https://github.com/nodeca/mincer)25- [JS-Git](https://github.com/creationix/js-git) and26 [Tedit](https://chrome.google.com/webstore/detail/tedit-development-environ/ooekdijbnbbjdfjocaiflnjgoohnblgf)27 by [@creationix](https://github.com/creationix)28 29 30__Benchmarks:__31 32```33node v0.10.26, 1mb sample:34 35 deflate-dankogai x 4.73 ops/sec ±0.82% (15 runs sampled)36 deflate-gildas x 4.58 ops/sec ±2.33% (15 runs sampled)37 deflate-imaya x 3.22 ops/sec ±3.95% (12 runs sampled)38 ! deflate-pako x 6.99 ops/sec ±0.51% (21 runs sampled)39 deflate-pako-string x 5.89 ops/sec ±0.77% (18 runs sampled)40 deflate-pako-untyped x 4.39 ops/sec ±1.58% (14 runs sampled)41 * deflate-zlib x 14.71 ops/sec ±4.23% (59 runs sampled)42 inflate-dankogai x 32.16 ops/sec ±0.13% (56 runs sampled)43 inflate-imaya x 30.35 ops/sec ±0.92% (53 runs sampled)44 ! inflate-pako x 69.89 ops/sec ±1.46% (71 runs sampled)45 inflate-pako-string x 19.22 ops/sec ±1.86% (49 runs sampled)46 inflate-pako-untyped x 17.19 ops/sec ±0.85% (32 runs sampled)47 * inflate-zlib x 70.03 ops/sec ±1.64% (81 runs sampled)48 49node v0.11.12, 1mb sample:50 51 deflate-dankogai x 5.60 ops/sec ±0.49% (17 runs sampled)52 deflate-gildas x 5.06 ops/sec ±6.00% (16 runs sampled)53 deflate-imaya x 3.52 ops/sec ±3.71% (13 runs sampled)54 ! deflate-pako x 11.52 ops/sec ±0.22% (32 runs sampled)55 deflate-pako-string x 9.53 ops/sec ±1.12% (27 runs sampled)56 deflate-pako-untyped x 5.44 ops/sec ±0.72% (17 runs sampled)57 * deflate-zlib x 14.05 ops/sec ±3.34% (63 runs sampled)58 inflate-dankogai x 42.19 ops/sec ±0.09% (56 runs sampled)59 inflate-imaya x 79.68 ops/sec ±1.07% (68 runs sampled)60 ! inflate-pako x 97.52 ops/sec ±0.83% (80 runs sampled)61 inflate-pako-string x 45.19 ops/sec ±1.69% (57 runs sampled)62 inflate-pako-untyped x 24.35 ops/sec ±2.59% (40 runs sampled)63 * inflate-zlib x 60.32 ops/sec ±1.36% (69 runs sampled)64```65 66zlib's test is partially affected by marshalling (that make sense for inflate only).67You can change deflate level to 0 in benchmark source, to investigate details.68For deflate level 6 results can be considered as correct.69 70__Install:__71 72node.js:73 74```75npm install pako76```77 78browser:79 80```81bower install pako82```83 84 85Example & API86-------------87 88Full docs - http://nodeca.github.io/pako/89 90```javascript91var pako = require('pako');92 93// Deflate94//95var input = new Uint8Array();96//... fill input data here97var output = pako.deflate(input);98 99// Inflate (simple wrapper can throw exception on broken stream)100//101var compressed = new Uint8Array();102//... fill data to uncompress here103try {104 var result = pako.inflate(compressed);105} catch (err) {106 console.log(err);107}108 109//110// Alternate interface for chunking & without exceptions111//112 113var inflator = new pako.Inflate();114 115inflator.push(chunk1, false);116inflator.push(chunk2, false);117...118inflator.push(chunkN, true); // true -> last chunk119 120if (inflator.err) {121 console.log(inflator.msg);122}123 124var output = inflator.result;125 126```127 128Sometime you can wish to work with strings. For example, to send129big objects as json to server. Pako detects input data type. You can130force output to be string with option `{ to: 'string' }`.131 132```javascript133var pako = require('pako');134 135var test = { my: 'super', puper: [456, 567], awesome: 'pako' };136 137var binaryString = pako.deflate(JSON.stringify(test), { to: 'string' });138 139//140// Here you can do base64 encode, make xhr requests and so on.141//142 143var restored = JSON.parse(pako.inflate(binaryString, { to: 'string' }));144```145 146 147Notes148-----149 150Pako does not contain some specific zlib functions:151 152- __deflate__ - methods `deflateCopy`, `deflateBound`, `deflateParams`,153 `deflatePending`, `deflatePrime`, `deflateTune`.154- __inflate__ - methods `inflateCopy`, `inflateMark`,155 `inflatePrime`, `inflateGetDictionary`, `inflateSync`, `inflateSyncPoint`, `inflateUndermine`.156- High level inflate/deflate wrappers (classes) may not support some flush157 modes. Those should work: Z_NO_FLUSH, Z_FINISH, Z_SYNC_FLUSH.158 159 160pako for enterprise161-------------------162 163Available as part of the Tidelift Subscription164 165The 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)166 167 168Authors169-------170 171- Andrey Tupitsin [@anrd83](https://github.com/andr83)172- Vitaly Puzrin [@puzrin](https://github.com/puzrin)173 174Personal thanks to:175 176- Vyacheslav Egorov ([@mraleph](https://github.com/mraleph)) for his awesome177 tutorials about optimising JS code for v8, [IRHydra](http://mrale.ph/irhydra/)178 tool and his advices.179- David Duponchel ([@dduponchel](https://github.com/dduponchel)) for help with180 testing.181 182Original implementation (in C):183 184- [zlib](http://zlib.net/) by Jean-loup Gailly and Mark Adler.185 186 187License188-------189 190- MIT - all files, except `/lib/zlib` folder191- ZLIB - `/lib/zlib` content192 