You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1021 B
JavaScript
34 lines
1021 B
JavaScript
module.exports = function (/*Buffer*/ inbuf) {
|
|
var zlib = require("zlib");
|
|
|
|
var opts = { chunkSize: (parseInt(inbuf.length / 1024) + 1) * 1024 };
|
|
|
|
return {
|
|
deflate: function () {
|
|
return zlib.deflateRawSync(inbuf, opts);
|
|
},
|
|
|
|
deflateAsync: function (/*Function*/ callback) {
|
|
var tmp = zlib.createDeflateRaw(opts),
|
|
parts = [],
|
|
total = 0;
|
|
tmp.on("data", function (data) {
|
|
parts.push(data);
|
|
total += data.length;
|
|
});
|
|
tmp.on("end", function () {
|
|
var buf = Buffer.alloc(total),
|
|
written = 0;
|
|
buf.fill(0);
|
|
for (var i = 0; i < parts.length; i++) {
|
|
var part = parts[i];
|
|
part.copy(buf, written);
|
|
written += part.length;
|
|
}
|
|
callback && callback(buf);
|
|
});
|
|
tmp.end(inbuf);
|
|
}
|
|
};
|
|
};
|