pako/README.md

176 wiersze
5.1 KiB
Markdown

2014-02-18 22:10:11 +00:00
pako - zlib port to javascript, very fast!
==========================================
2014-01-25 13:57:00 +00:00
2014-06-08 20:03:57 +00:00
[![Build Status](https://travis-ci.org/nodeca/pako.svg?branch=master)](https://travis-ci.org/nodeca/pako)
[![NPM version](https://img.shields.io/npm/v/pako.svg)](https://www.npmjs.org/package/pako)
2014-02-13 17:29:55 +00:00
2014-02-18 17:55:32 +00:00
__Why pako is cool:__
2014-02-24 04:53:24 +00:00
- Almost as fast in modern JS engines as C implementation (see benchmarks).
- Works in browsers, you can browserify any separate component.
2014-04-09 16:04:59 +00:00
- Chunking support for big blobs.
- Results are binary equal to well known [zlib](http://www.zlib.net/) (now v1.2.8 ported).
2014-02-18 17:55:32 +00:00
2014-02-24 04:53:24 +00:00
This project was done to understand how fast JS can be and is it necessary to
develop native C modules for CPU-intensive tasks. Enjoy the result!
2014-04-09 16:04:59 +00:00
__Famous projects, using pako:__
- [browserify](http://browserify.org/) (via [browserify-zlib](https://github.com/devongovett/browserify-zlib))
- [JSZip](http://stuk.github.io/jszip/)
- [mincer](https://github.com/nodeca/mincer)
2014-05-02 15:55:55 +00:00
- [JS-Git](https://github.com/creationix/js-git) and
[Tedit](https://chrome.google.com/webstore/detail/tedit-development-environ/ooekdijbnbbjdfjocaiflnjgoohnblgf)
by [@creatronix](https://github.com/creationix)
2014-04-09 16:04:59 +00:00
2014-02-18 17:55:32 +00:00
__Benchmarks:__
```
2014-03-14 08:02:01 +00:00
node v0.10.26, 1mb sample:
2014-04-13 12:00:26 +00:00
deflate-dankogai x 4.73 ops/sec ±0.82% (15 runs sampled)
deflate-gildas x 4.58 ops/sec ±2.33% (15 runs sampled)
deflate-imaya x 3.22 ops/sec ±3.95% (12 runs sampled)
! deflate-pako x 6.99 ops/sec ±0.51% (21 runs sampled)
deflate-pako-string x 5.89 ops/sec ±0.77% (18 runs sampled)
2014-04-13 12:00:26 +00:00
deflate-pako-untyped x 4.39 ops/sec ±1.58% (14 runs sampled)
* deflate-zlib x 14.71 ops/sec ±4.23% (59 runs sampled)
inflate-dankogai x 32.16 ops/sec ±0.13% (56 runs sampled)
inflate-imaya x 30.35 ops/sec ±0.92% (53 runs sampled)
! inflate-pako x 69.89 ops/sec ±1.46% (71 runs sampled)
inflate-pako-string x 19.22 ops/sec ±1.86% (49 runs sampled)
2014-04-13 12:00:26 +00:00
inflate-pako-untyped x 17.19 ops/sec ±0.85% (32 runs sampled)
* inflate-zlib x 70.03 ops/sec ±1.64% (81 runs sampled)
node v0.11.12, 1mb sample:
deflate-dankogai x 5.60 ops/sec ±0.49% (17 runs sampled)
deflate-gildas x 5.06 ops/sec ±6.00% (16 runs sampled)
deflate-imaya x 3.52 ops/sec ±3.71% (13 runs sampled)
! deflate-pako x 11.52 ops/sec ±0.22% (32 runs sampled)
deflate-pako-string x 9.53 ops/sec ±1.12% (27 runs sampled)
2014-04-13 12:00:26 +00:00
deflate-pako-untyped x 5.44 ops/sec ±0.72% (17 runs sampled)
* deflate-zlib x 14.05 ops/sec ±3.34% (63 runs sampled)
inflate-dankogai x 42.19 ops/sec ±0.09% (56 runs sampled)
inflate-imaya x 79.68 ops/sec ±1.07% (68 runs sampled)
! inflate-pako x 97.52 ops/sec ±0.83% (80 runs sampled)
inflate-pako-string x 45.19 ops/sec ±1.69% (57 runs sampled)
2014-04-13 12:00:26 +00:00
inflate-pako-untyped x 24.35 ops/sec ±2.59% (40 runs sampled)
* inflate-zlib x 60.32 ops/sec ±1.36% (69 runs sampled)
2014-02-18 17:55:32 +00:00
```
2014-03-14 08:02:01 +00:00
zlib's test is partialy afferted by marshling (that make sense for inflate only).
You can change deflate level to 0 in benchmark source, to investigate details.
For deflate level 6 results can be considered as correct.
2014-02-24 04:53:24 +00:00
2014-02-18 22:10:11 +00:00
__Install:__
2014-02-18 17:55:32 +00:00
2014-02-18 22:10:11 +00:00
node.js:
2014-02-18 17:55:32 +00:00
2014-02-18 22:10:11 +00:00
```
npm install pako
```
browser:
```
bower install pako
```
Example & API
-------------
2014-03-15 17:30:03 +00:00
Full docs - http://nodeca.github.io/pako/
2014-02-19 21:38:10 +00:00
2014-02-18 22:10:11 +00:00
```javascript
var pako = require('pako');
// Deflate
//
var input = new Uint8Array();
//... fill input data here
var output = pako.deflate(input);
2014-03-12 01:01:30 +00:00
// Inflate (simple wrapper can throw exception on broken stream)
2014-02-18 22:10:11 +00:00
//
var compressed = new Uint8Array();
//... fill data to uncompress here
2014-03-12 01:01:30 +00:00
try {
var result = pako.inflate(compressed);
2015-04-13 14:39:20 +00:00
} catch (err) {
2014-03-12 01:01:30 +00:00
console.log(err);
2014-02-18 22:10:11 +00:00
}
2014-03-12 01:01:30 +00:00
//
// Alternate interface for chunking & without exceptions
//
var inflator = new pako.Inflate();
inflator.push(chunk1, false);
inflator.push(chunk2, false);
...
2014-03-15 17:30:03 +00:00
inflator.push(chunkN, true); // true -> last chunk
2014-03-12 01:01:30 +00:00
if (inflator.err) {
console.log(inflator.msg);
}
var output = inflator.result;
2014-02-18 22:10:11 +00:00
```
2014-04-09 16:04:59 +00:00
Sometime you can wish to work with strings. For example, to send
2014-04-08 14:55:17 +00:00
big objects as json to server. Pako detects input data type. You can
force output to be string with option `{ to: 'string' }`.
```javascript
var pako = require('pako');
var test = { my: 'super', puper: [456, 567], awesome: 'pako' };
var binaryString = pako.deflate(JSON.stringify(test), { to: 'string' });
//
// Here you can do base64 encode, make xhr requests and so on.
//
var restored = JSON.parse(pako.inflate(binaryString, { to: 'string' }));
```
2014-02-18 17:55:32 +00:00
Notes
-----
2014-03-15 17:30:03 +00:00
Pako does not contain some specific zlib functions:
2014-02-18 17:55:32 +00:00
2014-04-17 22:56:41 +00:00
- __deflate__ - methods `deflateCopy`, `deflateBound`, `deflateParams`,
`deflatePending`, `deflatePrime`, `deflateSetDictionary`, `deflateTune`.
- __inflate__ - `inflateGetDictionary`, `inflateCopy`, `inflateMark`,
`inflatePrime`, `inflateSetDictionary`, `inflateSync`, `inflateSyncPoint`,
`inflateUndermine`.
2014-02-18 17:55:32 +00:00
2014-02-18 22:10:11 +00:00
2014-02-18 17:55:32 +00:00
Authors
-------
- Andrey Tupitsin [@anrd83](https://github.com/andr83)
2014-02-18 22:10:11 +00:00
- Vitaly Puzrin [@puzrin](https://github.com/puzrin)
2014-02-18 17:55:32 +00:00
2015-09-14 12:16:43 +00:00
Personal thanks to:
- Vyacheslav Egorov ([@mraleph](https://github.com/mraleph)) for his awesome
tutoruals about optimising JS code for v8, [IRHydra](http://mrale.ph/irhydra/)
tool and his advices.
- David Duponchel ([@dduponchel](https://github.com/dduponchel)) for help with
testing.
2014-02-18 17:55:32 +00:00
License
-------
2014-02-19 14:40:53 +00:00
MIT