Skip to content

Instantly share code, notes, and snippets.

@copy
Created March 5, 2015 23:14
Show Gist options
  • Save copy/dd19821f7d2e10545488 to your computer and use it in GitHub Desktop.
Save copy/dd19821f7d2e10545488 to your computer and use it in GitHub Desktop.
Iuppiter.decompress = function(sstart, slen, dstart)
{
slen = slen | 0;
var
src = 0,
dst = 0,
cpy = 0,
copymap = 0,
copymask = 1 << (NBBY - 1 | 0),
mlen = 0,
offset = 0;
//var avg_mlen = [];
while (src < slen)
{
if ((copymask <<= 1) === (1 << NBBY))
{
copymask = 1;
copymap = sstart[src];
src = src + 1 | 0;
}
if (copymap & copymask)
{
mlen = (sstart[src] >> (NBBY - MATCH_BITS | 0)) + MATCH_MIN | 0;
offset = ((sstart[src] << NBBY) | sstart[src + 1 | 0]) & OFFSET_MASK;
src = src + 2 | 0;
cpy = dst - offset | 0;
//if (cpy >= 0)
{
//console.log(mlen);
//avg_mlen.push(mlen);
//dstart.set(dstart.subarray(cpy, cpy + mlen | 0), dst);
//dst = dst + mlen | 0;
//cpy = cpy + mlen | 0;
//mlen = mlen - 1 | 0;
while (mlen > 4)
{
dstart[dst] = dstart[cpy];
dst = dst + 1 | 0;
cpy = cpy + 1 | 0;
dstart[dst] = dstart[cpy];
dst = dst + 1 | 0;
cpy = cpy + 1 | 0;
dstart[dst] = dstart[cpy];
dst = dst + 1 | 0;
cpy = cpy + 1 | 0;
dstart[dst] = dstart[cpy];
dst = dst + 1 | 0;
cpy = cpy + 1 | 0;
mlen = mlen - 4 | 0;
}
while (mlen > 0)
{
dstart[dst] = dstart[cpy];
dst = dst + 1 | 0;
cpy = cpy + 1 | 0;
mlen = mlen - 1 | 0;
}
}
//else
//{
// /*
// * offset before start of destination buffer
// * indicates corrupt source data
// */
// console.warn("possibly corrupt data");
// return dstart;
//}
}
else
{
dstart[dst] = sstart[src];
dst = dst + 1 | 0;
src = src + 1 | 0;
}
}
//console.log(avg_mlen.reduce(function(a, x) { return a + x; }, 0) / avg_mlen.length);
//console.assert(dstart.length >= dst);
//console.assert(sstart.length >= src);
return dstart;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment