TODO: Not Tested:
https://gist.github.com/revolunet/843889
LZW-compress a string
var LZWEncode = function(s, options) {
options = Object.assign({
predictor: 1,
colors: 1,
bitsPerComponent: 8,
columns: 1,
earlyChange: 1
}, options);
var dict = {};
var data = (s + "").split("");
var out = [];
var currChar;
var phrase = data[0];
var code = 256; //0xe000
for (var i=1; i<data.length; i++) {
currChar=data[i];
if (dict['_' + phrase + currChar] != null) {
phrase += currChar;
}
else {
out.push(phrase.length > 1 ? dict['_'+phrase] : phrase.charCodeAt(0));
dict['_' + phrase + currChar] = code;
code++;
phrase=currChar;
}
}
out.push(phrase.length > 1 ? dict['_'+phrase] : phrase.charCodeAt(0));
for (var i=0; i<out.length; i++) {
out[i] = String.fromCharCode(out[i]);
}
return out.join("");
}
Decompress an LZW-encoded string
var LZWDecode = function(s, options) {
options = Object.assign({
predictor: 1,
colors: 1,
bitsPerComponent: 8,
columns: 1,
earlyChange: 1
}, options);
var dict = {};
var data = (s + "").split("");
var currChar = data[0];
var oldPhrase = currChar;
var out = [currChar];
var code = 256;
var phrase;
for (var i=1; i<data.length; i++) {
var currCode = data[i].charCodeAt(0);
if (currCode < 256) {
phrase = data[i];
}
else {
phrase = dict['_'+currCode] ? dict['_'+currCode] : (oldPhrase + currChar);
}
out.push(phrase);
currChar = phrase.charAt(0);
dict['_'+code] = oldPhrase + currChar;
code++;
oldPhrase = phrase;
}
return out.join("");
}
function ASCIIHexEncode(value) {
    var result = '';
    var i;

    for (var i = 0; i < value.length; i += 1) {
      result += ("0" + value.charCodeAt(i).toString(16)).slice(-2);
    }

    result += '>';
    return result;
  }