mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-04 10:50:59 +01:00
updated zlib benchmark to use streams
This commit is contained in:
parent
ae49f96738
commit
ff0a4c0c50
2 changed files with 31 additions and 2 deletions
0
benchmark/benchmark.js
Normal file → Executable file
0
benchmark/benchmark.js
Normal file → Executable file
|
@ -5,6 +5,35 @@ var zlib = require('zlib');
|
|||
exports.async = true;
|
||||
|
||||
exports.run = function(data, callback) {
|
||||
var buffer = new Buffer(data);
|
||||
zlib.deflate(buffer, callback);
|
||||
//zlib.deflate(new Buffer(data), callback);
|
||||
|
||||
var zlibStream = zlib.createDeflate({
|
||||
chunkSize: 1*1024*1024/*,
|
||||
level: 6*/
|
||||
});
|
||||
var buffers = [], nread = 0;
|
||||
|
||||
|
||||
zlibStream.on('error', function(err) {
|
||||
zlibStream.removeAllListeners();
|
||||
zlibStream=null;
|
||||
callback(err);
|
||||
});
|
||||
|
||||
zlibStream.on('data', function(chunk) {
|
||||
buffers.push(chunk);
|
||||
nread += chunk.length;
|
||||
});
|
||||
|
||||
zlibStream.on('end', function() {
|
||||
zlibStream.removeAllListeners();
|
||||
zlibStream=null;
|
||||
|
||||
var buffer = Buffer.concat(buffers);
|
||||
|
||||
callback(null);
|
||||
});
|
||||
|
||||
zlibStream.write(new Buffer(data));
|
||||
zlibStream.end();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue