lzbase62
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 large amounts of data in size-limited storage such as localStorage or cookies.
Demo
Installation
npm
$ npm install --save lzbase62
Usage
var data = 'hello hello hello';console; // 17 var compressed = lzbase62;console; // 'tYVccfrgxGL'console; // 11console; // true var decompressed = lzbase62;console; // 'hello hello hello'console; // true
node
const lzbase62 = ;const compressed = lzbase62;
webpack etc.
;const compressed = lzbase62;
browser (standalone)
Object lzbase62 is defined in the global scope if running in the browser window. ( window.lzbase62
)
API
lzbase62.compress(data, [options])
Compress data to a base62 [0-9a-zA-Z]
encoded string.
Arguments
- data (string) : Input data
- [options] (object) : Compress options
- onData (function (data) {}) : Called when a data is chunked
- onEnd (function () {}) : Called when process is finished
Returns
(string) : Compressed data
Example
Compress string
var compressed = lzbase62;console; // 'tRSTxDM'
Compress data using onData events
var string = 'hello hello hello';var compressed = ; lzbase62;
lzbase62.decompress(data, [options])
Decompress data from a base62 [0-9a-zA-Z]
encoded string.
Arguments
- data (string) : Input data
- [options] (object) : Decompress options
- onData (function (data) {}) : Called when a data is chunked
- onEnd (function () {}) : Called when process is finished
Returns
(string) : Decompressed data
Example
Decompress string
var decompressed = lzbase62;console; // 'abcabcabcabcabc'
Decompress data using onData events
var compressed = 'tYVccfrgxGL';var decompressed = ; lzbase62;
License
MIT