JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1362
  • Score
    100M100P100Q100157F
  • License MIT

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

Package Exports

  • lzbase62

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lzbase62) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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');

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