mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-22 04:43:47 +01:00
Added high-level inflator stubs
This commit is contained in:
parent
dcc28b5b27
commit
7254746060
1 changed files with 59 additions and 19 deletions
|
@ -1,33 +1,73 @@
|
||||||
var z_inflate = require('zlib/inflate.js');
|
'use strict';
|
||||||
|
|
||||||
|
//var z_inflate = require('./zlib/inflate');
|
||||||
|
var utils = require('./zlib/utils');
|
||||||
|
|
||||||
|
|
||||||
var Inflate = function(options) {
|
var Inflate = function(/*options*/) {
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
Inflate.prototype.push = function(input) {
|
Inflate.prototype.push = function(/*data_in*/) {
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
Inflate.prototype.finish = function() {
|
Inflate.prototype.finish = function() {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
Inflate.prototype.onData = function(/*data_out*/) {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
Inflate.prototype.onEnd = function(/*error*/) {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
function inflate (input, options) {
|
||||||
|
var result;
|
||||||
|
var chains = [];
|
||||||
|
var inflator = new Inflate(options);
|
||||||
|
|
||||||
|
inflator.onData = function(data_out) {
|
||||||
|
chains.push(data_out);
|
||||||
|
};
|
||||||
|
|
||||||
|
inflator.onEnd = function(error) {
|
||||||
|
var i, l, len, pos, chain;
|
||||||
|
|
||||||
|
if (error) { throw error; }
|
||||||
|
|
||||||
|
// calculate data length
|
||||||
|
len = 0;
|
||||||
|
for (i=0, l=chains.length; i<l; i++) {
|
||||||
|
len += chains[i].length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// join chains
|
||||||
|
result = utils.arrayCreate(len);
|
||||||
|
pos = 0;
|
||||||
|
|
||||||
|
for (i=0, l=chains.length; i<l; i++) {
|
||||||
|
chain = chains[i];
|
||||||
|
len = chain.length;
|
||||||
|
utils.arraySet(result, chain, 0, len, pos);
|
||||||
|
pos += len;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inflator.push(input);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Inflate.prototype.onData = function(output) {
|
function inflateRaw (input, options) {
|
||||||
|
options = options || {};
|
||||||
}
|
options.raw = true;
|
||||||
|
return inflate(input, options);
|
||||||
Inflate.prototype.onEnd = function(error) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Inflate = Inflate;
|
exports.Inflate = Inflate;
|
||||||
|
exports.inflate = inflate;
|
||||||
exports.inflate = function(input, options) {
|
exports.inflateRaw = inflateRaw;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.inflateRaw = function(input, options) {
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue