From ff0a4c0c501d57f8f1966ac3eaa4baf8d3d2cbeb Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Tue, 4 Feb 2014 00:54:27 +0400 Subject: [PATCH] updated zlib benchmark to use streams --- benchmark/benchmark.js | 0 .../implementations/deflate-zlib/index.js | 33 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) mode change 100644 => 100755 benchmark/benchmark.js diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js old mode 100644 new mode 100755 diff --git a/benchmark/implementations/deflate-zlib/index.js b/benchmark/implementations/deflate-zlib/index.js index 6ed1cb9..88f6134 100644 --- a/benchmark/implementations/deflate-zlib/index.js +++ b/benchmark/implementations/deflate-zlib/index.js @@ -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(); }