{"_id":"compressjs","_rev":"4176615","name":"compressjs","description":"pure JavaScript de/compression (bzip2, etc) for node.js, volo, and the browser.","dist-tags":{"latest":"1.0.3"},"maintainers":[{"name":"cscott","email":"cscott@cscott.net"}],"time":{"modified":"2026-03-01T21:35:07.000Z","created":"2013-04-09T20:29:48.656Z","1.0.3":"2015-07-27T19:42:37.174Z","1.0.2":"2014-10-10T03:35:09.073Z","1.0.1":"2013-10-16T17:50:00.780Z","1.0.0":"2013-04-09T20:29:48.656Z"},"users":{},"author":{"name":"C. Scott Ananian"},"repository":{"type":"git","url":"https://github.com/cscott/compressjs.git"},"versions":{"1.0.3":{"name":"compressjs","version":"1.0.3","author":{"name":"C. Scott Ananian"},"description":"pure JavaScript de/compression (bzip2, etc) for node.js, volo, and the browser.","keywords":["bzip2","compression","decompression"],"main":"main","repository":{"type":"git","url":"https://github.com/cscott/compressjs.git"},"license":"GPL","bin":{"compressjs":"./bin/compressjs"},"directories":{"test":"test"},"dependencies":{"amdefine":"~1.0.0","commander":"~2.8.1"},"devDependencies":{"mocha":"~2.2.5"},"scripts":{"test":"mocha"},"amd":{},"volo":{},"gitHead":"288ef0043e0eed00e5fb23a882424a022b39bf92","bugs":{"url":"https://github.com/cscott/compressjs/issues"},"homepage":"https://github.com/cscott/compressjs","_id":"compressjs@1.0.3","_shasum":"95db74dd5b9038cf80bca321ab0ede271b4959b6","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"cscott","email":"cscott@cscott.net"},"maintainers":[{"name":"cscott","email":"cscott@cscott.net"}],"dist":{"shasum":"95db74dd5b9038cf80bca321ab0ede271b4959b6","size":1326884,"noattachment":false,"key":"/compressjs/-/compressjs-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/compressjs/download/compressjs-1.0.3.tgz"},"publish_time":1438026157174,"_hasShrinkwrap":false,"_cnpm_publish_time":1438026157174,"_cnpmcore_publish_time":"2021-12-16T17:31:38.375Z"},"1.0.2":{"name":"compressjs","version":"1.0.2","author":{"name":"C. Scott Ananian"},"description":"pure JavaScript de/compression (bzip2, etc) for node.js, volo, and the browser.","keywords":["bzip2","compression","decompression"],"main":"main","repository":{"type":"git","url":"https://github.com/cscott/compressjs.git"},"license":"GPL","bin":{"compressjs":"./bin/compressjs"},"directories":{"test":"test"},"dependencies":{"amdefine":"~0.1.0","commander":"~2.3.0"},"devDependencies":{"mocha":"~1.21.4"},"scripts":{"test":"mocha"},"amd":{},"volo":{},"gitHead":"98e463fdf7c85fc8502999f1f6fed5b959c6dde0","bugs":{"url":"https://github.com/cscott/compressjs/issues"},"homepage":"https://github.com/cscott/compressjs","_id":"compressjs@1.0.2","_shasum":"46f4823d3661f536c5d2900a8ea567b01337be95","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"cscott","email":"cscott@cscott.net"},"maintainers":[{"name":"cscott","email":"cscott@cscott.net"}],"dist":{"shasum":"46f4823d3661f536c5d2900a8ea567b01337be95","size":1326858,"noattachment":false,"key":"/compressjs/-/compressjs-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/compressjs/download/compressjs-1.0.2.tgz"},"publish_time":1412912109073,"_hasShrinkwrap":false,"_cnpm_publish_time":1412912109073,"_cnpmcore_publish_time":"2021-12-16T17:31:39.205Z"},"1.0.1":{"name":"compressjs","version":"1.0.1","author":{"name":"C. Scott Ananian"},"description":"pure JavaScript de/compression (bzip2, etc) for node.js, volo, and the browser.","keywords":["bzip2","compression","decompression"],"main":"main","repository":{"type":"git","url":"https://github.com/cscott/compressjs.git"},"license":"GPL","bin":{"compressjs":"./bin/compressjs"},"directories":{"test":"test"},"dependencies":{"amdefine":"~0.1.0","commander":"~2.0.0"},"devDependencies":{"mocha":"~1.13.0"},"scripts":{"test":"mocha"},"amd":{},"volo":{},"readmeFilename":"README.md","bugs":{"url":"https://github.com/cscott/compressjs/issues"},"_id":"compressjs@1.0.1","dist":{"shasum":"09687d6c0f666eb8ab0364a8295602845e2568fc","size":1326320,"noattachment":false,"key":"/compressjs/-/compressjs-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/compressjs/download/compressjs-1.0.1.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"cscott","email":"cscott@cscott.net"},"maintainers":[{"name":"cscott","email":"cscott@cscott.net"}],"publish_time":1381945800780,"_hasShrinkwrap":false,"_cnpm_publish_time":1381945800780,"_cnpmcore_publish_time":"2021-12-16T17:31:39.888Z"},"1.0.0":{"name":"compressjs","version":"1.0.0","author":{"name":"C. Scott Ananian"},"description":"pure JavaScript de/compression (bzip2, etc) for node.js, volo, and the browser.","keywords":["bzip2","compression","decompression"],"main":"main","repository":{"type":"git","url":"git://github.com/cscott/compressjs.git"},"license":"GPL","bin":{"compressjs":"./bin/compressjs"},"directories":{"test":"test"},"dependencies":{"amdefine":"~0.0.4","commander":"~1.1.1"},"devDependencies":{"mocha":"~1.9.0"},"scripts":{"test":"mocha"},"amd":{},"volo":{},"_npmUser":{"name":"cscott","email":"cscott@cscott.net"},"_id":"compressjs@1.0.0","optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.19","_defaultsLoaded":true,"dist":{"shasum":"54af706e6ef5af49b216082b5effc3b670e543d1","size":1328098,"noattachment":false,"key":"/compressjs/-/compressjs-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/compressjs/download/compressjs-1.0.0.tgz"},"maintainers":[{"name":"cscott","email":"cscott@cscott.net"}],"publish_time":1365539388656,"_hasShrinkwrap":false,"_cnpm_publish_time":1365539388656,"_cnpmcore_publish_time":"2021-12-16T17:31:40.598Z"}},"readme":"# compressjs\n[![NPM][NPM1]][NPM2]\n\n[![Build Status][1]][2] [![dependency status][3]][4] [![dev dependency status][5]][6]\n\n`compressjs` contains fast pure-JavaScript implementations of various\nde/compression algorithms, including `bzip2`, Charles Bloom's\n[LZP3](http://www.cbloom.com/papers/lzp.pdf),\na modified\n[LZJB](http://en.wikipedia.org/wiki/LZJB),\n`PPM-D`, and an implementation of\n[Dynamic Markov Compression](http://en.wikipedia.org/wiki/Dynamic_Markov_Compression).\n`compressjs` is written by C. Scott Ananian.\nThe Range Coder used is a JavaScript port of\n[Michael Schindler's C range coder](http://www.compressconsult.com/rangecoder).\nBits also also borrowed from Yuta Mori's\n[SAIS implementation](https://sites.google.com/site/yuta256/sais);\n[Eli Skeggs](https://github.com/skeggse/node-bzip),\n[Kevin Kwok](https://github.com/antimatter15/bzip2.js),\n[Rob Landley](http://www.landley.net/code/bunzip-4.1.c),\n[James Taylor](https://bitbucket.org/james_taylor/seek-bzip2/),\nand [Matthew Francis](https://code.google.com/p/jbzip2)\nfor Bzip2 compression and decompression code.\n\"Bear\" wrote the [original JavaScript LZJB](https://code.google.com/p/jslzjb/);\nthe version here is based on the\n[node lzjb module](https://github.com/cscott/lzjb).\n\n## Compression benchmarks\nHere are some representative speeds and sizes for the various algorithms\nimplemented in this package.  Times are with node 0.8.22 on my laptop, but\nthey should be valid for inter-algorithm comparisons.\n\n### test/sample5.ref\nThis is the [Taoism](http://simple.wikipedia.org/wiki/Taoism) article from\nthe [Simple English wikipedia](http://simple.wikipedia.org), in HTML\nformat as generated by the Wikipedia\n[Parsoid](http://www.mediawiki.org/wiki/Parsoid) project.\n\n|Type|Level|Size (bytes)|Compress time (s)|Decompress time (s)|\n|----|:---:|-----------:|----------------:|------------------:|\n|bwtc    |9| 272997|13.10| 1.85|\n|bzip2   |9| 275087|22.57| 1.21|\n|lzp3    |-| 292978| 1.73| 1.74|\n|ppm     |-| 297220|42.05|44.04|\n|bzip2   |1| 341615|22.63| 1.40|\n|bwtc    |1| 345764|12.34| 0.80|\n|dmc     |-| 434182| 6.97| 9.00|\n|lzjbr   |9| 491476| 3.19| 1.92|\n|lzjbr   |1| 523780| 2.76| 2.02|\n|lzjb    |9| 706210| 1.02| 0.30|\n|lzjb    |1| 758467| 0.66| 0.29|\n|context1|-| 939098| 5.20| 4.69|\n|fenwick |-|1440645| 3.06| 3.72|\n|mtf     |-|1441763| 1.92| 3.86|\n|huffman |-|1452055| 7.15| 6.56|\n|simple  |-|1479143| 0.72| 2.42|\n|defsum  |-|1491107| 3.19| 1.46|\n|no      |-|2130648| 0.80| 0.92|\n|-       |-|2130640|-    |-    |\n\n### enwik8\nThis test data is the first 10<sup>8</sup> bytes of the English Wikipedia\nXML dump on March 3, 2006.  This is the data set used for the\n[Large Text Compression Benchmark](http://mattmahoney.net/dc/text.html).\nIt can be downloaded [from that site](http://mattmahoney.net/dc/textdata.html).\n\n|Type|Level|Size (bytes)|Compress time (s)|Decompress time (s)|\n|----|:---:|-----------:|----------------:|------------------:|\n|ppm     |-|    26560169|2615.82|2279.17|\n|bzip2   |9|    28995650|1068.51|  66.95|\n|bwtc    |9|    29403626| 618.63| 112.00|\n|bzip2   |1|    33525893|1035.29|  66.98|\n|lzp3    |-|    34305420| 123.69| 167.77|\n|bwtc    |1|    34533422| 618.61|  43.52|\n|lzjbr   |9|    43594841| 242.60| 141.51|\n|lzjbr   |1|    44879071| 207.38| 147.14|\n|context1|-|    48480225| 253.48| 223.30|\n|huffman |-|    62702157| 301.50| 267.31|\n|fenwick |-|    62024449| 143.49| 164.15|\n|mtf     |-|    62090746|  83.62| 168.03|\n|simple  |-|    63463479|  27.79|  92.84|\n|defsum  |-|    64197615|  75.48|  32.05|\n|lzjb    |9|    64992459|  63.75|   5.90|\n|lzjb    |1|    67828511|  29.26|   5.89|\n|no      |-|   100000008|  26.29|  31.98|\n|-       |-|   100000000|      -|      -|\n\n### Algorithm descriptions\n* `compressjs.Bzip2` (`-t bzip2`) is the bzip2 algorithm we all have\n  come to know and love.  It has a block size between 100k and 900k.\n* `compressjs.BWTC` (`-t bwtc`) is substantially the same, but with a\n  few simplifications/improvements which make it faster, smaller, and\n  not binary-compatible.  In particular, the unnecessary initial RLE step\n  of bzip2 is omitted, and we use a range coder with an adaptive\n  context-0 model after the MTF/RLE2 step, instead of the static\n  huffman codes of bzip2.\n* `compressjs.PPM` (`-t ppm`) is a naive/simple implementation of the\n  [PPMD](http://en.wikipedia.org/wiki/Prediction_by_partial_matching)\n  algorithm with a 256k sliding window.\n* `compressjs.Lzp3` (`-t lzp3`) is an algorithm similar to Charles\n  Bloom's [LZP3](http://www.cbloom.com/papers/lzp.pdf) algorithm.\n  It uses a 1M sliding window, a context-4 model, and a range coder.\n* `compressjs.Dmc` (`-t dmc`) is a partial implementation of [Dynamic\n  Markov Compression](http://en.wikipedia.org/wiki/Dynamic_Markov_compression).\n  Unlike most DMC implementations, our implementation is bytewise (not\n  bitwise).  There is currently no provision for shrinking the Markov\n  model (or throwing it out when it grows too large), so be careful\n  with large inputs!  I may return to twiddle with this some more; see\n  the source for details.\n* `compressjs.Lzjb` (`-t lzjb`) is a straight copy of the fast\n  [LZJB](http://en.wikipedia.org/wiki/LZJB) algorithm from\n  <https://github.com/cscott/lzjb>.\n* `compressjs.LzjbR` (`-t lzjbr`) is a hacked version of LZJB which\n  uses a range coder and a bit of modeling instead of the fixed\n  9-bit literal / 17-bit match format of the original.\n\nThe remaining algorithms are self-tests for various bits of\ncompression code, not real compressors. `Context1Model` is a simple\nadaptive context-1 model using a range coder.  `Huffman` is an\nadaptive Huffman coder using [Vitter's algorithm][].\n`MTFModel`, `FenwickModel`, and `DefSumModel` are simple adaptive\ncontext-0 models with escapes, implementing using a move-to-front\nlist, a [Fenwick tree](http://en.wikipedia.org/wiki/Fenwick_tree), and\nCharles Bloom's\n[deferred summation algorithm](http://cbloom.com/papers/context.pdf),\nrespectively.  `Simple` is a static context-0 model for the range\ncoder.  `NoModel` encodes the input bits directly; it shows the\nbasic I/O overhead, as well as the few bytes of overhead due to the\n[file magic][] and a variable-length encoding of the uncompressed size\nof the file.\n\n[Vitter's algorithm]: http://en.wikipedia.org/wiki/Adaptive_Huffman_coding#Vitter_algorithm\n[file magic]:         http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Magic_numbers_in_files\n\n## How to install\n\n```\nnpm install compressjs\n```\nor\n```\nvolo add cscott/compressjs\n```\n\nThis package uses\n[Typed Arrays](https://developer.mozilla.org/en-US/docs/JavaScript/Typed_arrays)\nif available, which are present in node.js >= 0.5.5 and many modern\nbrowsers.  Full browser compatibility table\nis available at [caniuse.com](http://caniuse.com/typedarrays); briefly:\nIE 10, Firefox 4, Chrome 7, or Safari 5.1.\n\n## Testing\n\n```\nnpm install\nnpm test\n```\n\n## Usage\n\nThere is a binary available in bin:\n```\n$ bin/compressjs --help\n$ echo \"Test me\" | bin/compressjs -t lzp3 -z > test.lzp3\n$ bin/compressjs -t lzp3 -d test.lzp3\nTest me\n```\n\nThe `-t` argument can take a number of different strings to specify\nthe various compression algorithms available.  Use `--help` to see\nthe various options.\n\nFrom JavaScript:\n```\nvar compressjs = require('compressjs');\nvar algorithm = compressjs.Lzp3;\nvar data = new Buffer('Example data', 'utf8');\nvar compressed = algorithm.compressFile(data);\nvar decompressed = algorithm.decompressFile(compressed);\n// convert from array back to string\nvar data2 = new Buffer(decompressed).toString('utf8');\nconsole.log(data2);\n```\nThere is a streaming interface as well.  Use `Uint8Array` or normal\nJavaScript arrays when running in a browser.\n\nSee the tests in the `tests/` directory for further usage examples.\n\n## Documentation\n\n`require('compressjs')` returns a `compressjs` object.  Its fields\ncorrespond to the various algorithms implemented, which export one of\ntwo different interfaces, depending on whether it is a \"compression\nmethod\" or a \"model/coder\".\n\n### Compression Methods\nCompression methods (like `compressjs.Lzp3`) export two methods.\nThe first is a function accepting one, two or three parameters:\n\n`cmp.compressFile = function(input, [output], [Number compressionLevel] or [props])`\n\nThe `input` argument can be a \"stream\" object (which must implement the\n`readByte` method), or a `Uint8Array`, `Buffer`, or array.\n\nIf you omit the second argument, `compressFile` will return a JavaScript\narray containing the byte values of the compressed data.  If you pass\na second argument, it must be a \"stream\" object (which must implement the\n`writeByte` method).\n\nThe third argument may be omitted, or a number between 1 and 9 indicating\na compression level (1 being largest/fastest compression and 9 being\nsmallest/slowest compression).  Some algorithms also permit passing\nan object for finer-grained control of various compression properties.\n\nThe second exported method is a function accepting one or two parameters:\n\n`cmp.decompressFile = function(input, [output])`\n\nThe `input` parameter is as above.\n\nIf you omit the second argument, `decompressFile` will return a\n`Uint8Array`, `Buffer` or JavaScript array with the decompressed\ndata, depending on what your platform supports.  For most modern\nplatforms (modern browsers, recent node.js releases) the returned\nvalue will be a `Uint8Array`.\n\nIf you provide the second argument, it must be a \"stream\", implementing\nthe `writeByte` method.\n\n### Models and coders\n\nThe second type of object implemented is a model/coder.  `Huffman` and\n`RangeCoder` share the same interface as the simple context-0 probability\nmodels `MTFModel`, `FenwickModel`, `LogDistanceModel`, and\n`DeflateDistanceModel`.\n\n`model.factory = function(parameters)`\n\nThis method returns a function which can be invoked with a `size` argument to\ncreate a new instance of this model with the given parameters (which usually\ninclude the input/output stream or coder).\n\n`model.encode = function(symbol, [optional context])`\n\nThis method encodes the given symbol, possibly with the given additional\ncontext, and then updates the model or adaptive coder if necessary.\nThe symbol is usually in the range `[0, size)`, although some\nmodels allow adding \"extra symbols\" to the possible range, which are\nusually given negative values.  For example, you might want to create a\n`LogDistanceModel` with one extra state to encode \"same distance as the\nlast one encoded\".\n\n`model.decode = function([optional context])`\n\nDecode the next symbol and updates the model or adaptive coder.\nThe values returned are usually in the range `[0, size]` although\nnegative numbers may be returned if you requested \"extra symbols\" when\nyou created the model.\n\n## Related articles and projects\n\n* http://en.wikipedia.org/wiki/Dynamic_Markov_Compression Wikipedia article on DMC\n* http://www.cs.uvic.ca/~nigelh/Publications/DMC.pdf Original DMC paper\n* http://www.compressconsult.com/rangecoder/ Range Coder implementation in C\n\n## Other JavaScript compressors\n\n* https://github.com/cscott/lzjb LZJB\n* https://github.com/cscott/lzma-purejs LZMA\n* https://github.com/cscott/seek-bzip random-access bzip2 decompression\n\n## License (GPLv2)\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 2 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program.  If not, see http://www.gnu.org/licenses/.\n\n[NPM1]: https://nodei.co/npm/compressjs.png\n[NPM2]: https://nodei.co/npm/compressjs/\n\n[1]: https://travis-ci.org/cscott/compressjs.png\n[2]: https://travis-ci.org/cscott/compressjs\n[3]: https://david-dm.org/cscott/compressjs.png\n[4]: https://david-dm.org/cscott/compressjs\n[5]: https://david-dm.org/cscott/compressjs/dev-status.png\n[6]: https://david-dm.org/cscott/compressjs#info=devDependencies\n","_attachments":{},"homepage":"https://github.com/cscott/compressjs","bugs":{"url":"https://github.com/cscott/compressjs/issues"},"license":"GPL"}