24 lines
591 B
JavaScript
24 lines
591 B
JavaScript
var _deflate = (function() {
|
|
var _deflateRaw = (function() {
|
|
return function deflateRaw(data, out) {
|
|
var boff = 0;
|
|
while(boff < data.length) {
|
|
var L = Math.min(0xFFFF, data.length - boff);
|
|
var h = boff + L == data.length;
|
|
/* TODO: this is only type 0 stored */
|
|
out.write_shift(1, +h);
|
|
out.write_shift(2, L);
|
|
out.write_shift(2, (~L) & 0xFFFF);
|
|
while(L-- > 0) out[out.l++] = data[boff++];
|
|
}
|
|
return out.l;
|
|
};
|
|
})();
|
|
|
|
return function(data) {
|
|
var buf = new_buf(50+Math.floor(data.length*1.1));
|
|
var off = _deflateRaw(data, buf);
|
|
return buf.slice(0, off);
|
|
};
|
|
})();
|