Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including lzbase62 with all npm packages installed. Try it out:

var lzbase62 = require("lzbase62")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

lzbase62 v1.4.9

LZ77(LZSS) based compression algorithm in base62 for JavaScript

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

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free