lzjs

Compression by LZ algorithm in JavaScript.

  • lzjs

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
lzjs
2511.3.08 years ago9 years agoMinified + gzip package size for lzjs in KB

Readme

lzjs
Build Status
Compression by LZ algorithm in JavaScript.
This is useful when storing the large data in a size limited storage (e.g., localStorage, cookie etc.).

Installation

In a browser:

<script src="lzjs.js"></script>

or
<script src="lzjs.min.js"></script>

The object named "lzjs" will defined in the global scope.

In Node.js:

npm install -g lzjs

var lzjs = require('lzjs');

bower:

bower install lzjs

Usage

compress/decompress

  • {string} lzjs.compress ( data )
Compress data.
@param {string|Buffer} data Input data
@return {string} Compressed data
  • {string} lzjs.decompress ( data )
Decompress data.
@param {string} data Input data
@return {string} Decompressed data

compressToBase64 / decompressFromBase64

  • {string} lzjs.compressToBase64 ( data )
Compress data to base64 string.
@param {string|Buffer} data Input data
@return {string} Compressed data
  • {string} lzjs.decompressFromBase64 ( data )
Decompress data from base64 string.
@param {string} data Input data
@return {string} Decompressed data
var data = 'hello hello hello';
var compressed = lzjs.compress(data);
console.log(compressed); // Outputs a compressed binary string
var decompressed = lzjs.decompress(compressed);
console.log(decompressed === data); // true

Command Line:

After npm install -g lzjs
Note that command line compression is only valid the UTF-8 encoded file.

Add file to archive

lzjs -a something.txt

Extract file

lzjs -x something.txt.lzjs

Demo

License

MIT