Skip to content
LZ77(LZSS) based compression algorithm in base62 for JavaScript.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.eslintrc.json
.gitignore
.npmignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
bower.json
lzbase62.js
lzbase62.min.js
lzbase62.min.js.map
package.json

README.md

lzbase62

Build Status

LZ77(LZSS) based compression algorithm in base62 for JavaScript.

The compressed result will be a string in base 62 (0-9A-Za-z) characters.
This is useful when storing the large data in a size limited storage (e.g., localStorage, cookie etc.).

Installation

In a browser:

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

or

<script src="lzbase62.min.js"></script>

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

In Node.js:

npm install lzbase62
var lzbase62 = require('lzbase62');

bower:

bower install lzbase62

Usage

  • {string} lzbase62.compress ( data [, options ] )
    Compress data to a base 62(0-9a-zA-Z) encoded string.
    @param {string|Buffer} data Input data
    @param {Object=} [options] Options
    @return {string} Compressed data

  • {string} lzbase62.decompress ( data [, options ] )
    Decompress data from a base 62(0-9a-zA-Z) encoded string.
    @param {string} data Input data
    @param {Object=} [options] Options
    @return {string} Decompressed data

var data = 'hello hello hello';
console.log(data.length); // 17

var compressed = lzbase62.compress(data);
console.log(compressed); // 'tYVccfrgxGL'
console.log(compressed.length); // 11
console.log(compressed.length < data.length); // true

var decompressed = lzbase62.decompress(compressed);
console.log(decompressed); // 'hello hello hello'
console.log(decompressed === data); // true

Options

onData

Called when a data is chunked.

Receive a chunked string data.

onEnd

Called when process is finished.

Compress data using onData events
var string = 'hello hello hello';
var compressed = [];
lzbase62.compress(string, {
  onData: function(data) {
    compressed.push(data);
  },
  onEnd: function() {
    console.log(compressed.join(''));
  }
});
Decompress data using onData events
var decompressed = [];
lzbase62.decompress(compressed, {
  onData: function(data) {
    decompressed.push(data);
  },
  onEnd: function() {
    console.log(decompressed.join(''));
  }
});

Demo

License

MIT

You can’t perform that action at this time.