mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-10 22:00:58 +01:00
Added high-level deflator stubs
This commit is contained in:
parent
3b20ccb154
commit
dcc28b5b27
2 changed files with 62 additions and 9 deletions
|
@ -1,7 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var zlib = require('zlib/deflate.js');
|
//var zlib_deflate = require('./zlib/deflate.js');
|
||||||
|
var utils = require('./zlib/utils');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,7 +11,7 @@ var zlib = require('zlib/deflate.js');
|
||||||
* @param {Object} [options] zlib options
|
* @param {Object} [options] zlib options
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
var Deflate = function(options) {
|
var Deflate = function(/*options*/) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ var Deflate = function(options) {
|
||||||
* Compresses the input data and fills output buffer with compressed data.
|
* Compresses the input data and fills output buffer with compressed data.
|
||||||
* @return {Array|Uint8Array} compressed data
|
* @return {Array|Uint8Array} compressed data
|
||||||
*/
|
*/
|
||||||
Deflate.prototype.deflate = function(input) {
|
Deflate.prototype.push = function(/*data_in*/) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,11 +32,11 @@ Deflate.prototype.finish = function() {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Deflate.prototype.onData = function(output) {
|
Deflate.prototype.onData = function(/*data_out*/) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Deflate.prototype.onEnd = function(error) {
|
Deflate.prototype.onEnd = function(/*err*/) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -49,11 +50,51 @@ exports.Deflate = Deflate;
|
||||||
* @param [options]
|
* @param [options]
|
||||||
* @returns {Array|Uint8Array}
|
* @returns {Array|Uint8Array}
|
||||||
*/
|
*/
|
||||||
exports.deflate = function(input, options) {
|
function deflate(input, options) {
|
||||||
|
var result;
|
||||||
|
var chains = [];
|
||||||
|
var deflator = new Deflate(options);
|
||||||
|
|
||||||
};
|
deflator.onData = function(data_out) {
|
||||||
|
chains.push(data_out);
|
||||||
|
};
|
||||||
|
|
||||||
|
deflator.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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
deflator.push(input);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.deflateRaw = function(input, options) {
|
function deflateRaw(input, options) {
|
||||||
|
options = options || {};
|
||||||
|
options.raw = true;
|
||||||
|
return deflate(input, options);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
|
||||||
|
exports.Deflate = Deflate;
|
||||||
|
exports.deflate = deflate;
|
||||||
|
exports.deflateRaw = deflateRaw;
|
12
lib/zlib/utils.js
Normal file
12
lib/zlib/utils.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
exports.arraySet = function(dest, src, src_offs, len, dest_offs) {
|
||||||
|
for(var i=0; i<len; i++) {
|
||||||
|
dest[dest_offs + i] = src[src_offs + i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.arrayCreate = function(length) {
|
||||||
|
return new Array(length);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue