Skip to content

Instantly share code, notes, and snippets.

@mwgamera
Created September 28, 2012 21:49
Show Gist options
  • Save mwgamera/3802251 to your computer and use it in GitHub Desktop.
Save mwgamera/3802251 to your computer and use it in GitHub Desktop.
require("fs").readFile("README.lzjs", "ascii", function(e, d) {
process.stdout.write(require("./lz.min.js").decode(d));
});
8Ap1Simple LZ decompression for Javascript.
NOTE: This file is 4AWGed :)
Format4Bjhtrivial and mostly ripped off LZ4 stream5AmCmat. The5BoN
important differenc4CQnthat 6-bit symbols of Base64url alphabet are
uwBwinstea4CVG bytes. Init4AVnsingle character token in each record
is splitpB6two 3oBKfield4EoKFirst (higher) de4Apbbes length of
literal, second (lowFAawD9 matchCB8oAis folgByd byNCc
6AwDs encodingAFI4C7Fset (1-4095)4DwJbig-endian order4E0Jt may
have valuegGA0 ifABK7CoDends with iBW. OHCCDxIZ
extenXC5AofDDf4IbA (if itQF7elEFO4EEAs maxim9BEEi.e.
7). EJHFi7E3BvariableMAt,DCuoKn(63) SIGievG3A
nextqEdstillBAeEBCpHe. AfAI9_C6HNcomes optionalCFahH2done5FPFhe same mannZBeSeeABpAMl5L-U
details, it's really short5I7Mexplains everythingJAkngBJthertFFmes
aDI04BtAly (not5G-Cat becausADffOZAway6HTC handles
gOps, t5LDCmay resul4IOSinteroperability problemsEHC4L9Acontent5N8Jnot limited to 74OyCASCII!)
FNwDNuDM39MRD header aswQ2d abov7So_B:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_
CQSJorACnwM5providDEj4DGOI wasn't bored enough5GoAwrite agQZ
onehDD jus4HCB extreme5UgVlow direct exhaustive searchBO94RLNes
quickly hacked upYRzLua5FPF'm certainlyQPEgo7KYDto publishZVFrapBVh5QQAprogram4PQGree software.CLEAOzQJiou4L9Iy warranty, to
BOq4G9Bt permit6NjCby applic4GxDaw. You caQQMdi4DZFbute it
and/4HKEodify it unANUhV3termANhgWVDo WAW7hBNFuck4DZCWant
To P5ZWHc License, VerQIT2,DD0CTk4NcFSam Hocevar.6F2a
http://sam.zoy.org/wtfpl/COPYINGjN2ore QAA.
(function(lz) {
"use strict";
var base = (function() {
var a = new (typeof Uint8Array != "undefined" ? Uint8Array : Array)(256);
var b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
for (var i = 0; i < b.length; i++) a[b.charCodeAt(i)] = i;
return a;
})();
/*
* klg.lz.decode(zstring)
* Uncompress LZ-compressed string.
*/
lz["decode"] = function(z) {
var s = "", zp = 0;
while (zp < z.length) {
var m = base[z.charCodeAt(zp++)];
var l = m >>> 3 & 7; m &= 7;
var o = base[z.charCodeAt(zp++)] << 6;
o |= base[z.charCodeAt(zp++)];
var x;
// literal extended length
if (l == 7) {
do l += x = base[z.charCodeAt(zp++)];
while (x == 63);
}
// match extended length
if (m == 7) {
do m += x = base[z.charCodeAt(zp++)];
while (x == 63);
}
// literal
if (l) {
s += z.substr(zp, l);
zp += l;
}
// match-copy
if (o)
s += s.substr(s.length-o-m-3, m+4);
}
return s;
};
})(
"undefined" !== typeof module && module.exports ||
((window.klg || (window.klg = {})).lz = {})
);
(function(i){"use strict";var f=function(){for(var b=new ("undefined"!=typeof Uint8Array?Uint8Array:Array)(256),a=0;64>a;a++)b["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".charCodeAt(a)]=a;return b}();i.decode=function(b){for(var a="",c=0;c<b.length;){var d=f[b.charCodeAt(c++)],e=d>>>3&7,d=d&7,g=f[b.charCodeAt(c++)]<<6,g=g|f[b.charCodeAt(c++)],h;if(7==e){do e+=h=f[b.charCodeAt(c++)];while(63==h)}if(7==d){do d+=h=f[b.charCodeAt(c++)];while(63==h)}e&&(a+=b.substr(c,e),c+=e);g&&(a+=a.substr(a.length-
g-d-3,d+4))}return a}})("undefined"!==typeof module&&module.exports||((window.klg||(window.klg={})).lz={}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment