From e721e585cd5f14bcba2b5e4e0a09f076238c0b61 Mon Sep 17 00:00:00 2001 From: Christopher John Date: Mon, 17 Sep 2012 12:30:54 -0400 Subject: [PATCH] spawn ends on the close event in node version greater than 7 --- lib/gzip.js | 3 ++- test/helpers/index.js | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/gzip.js b/lib/gzip.js index 7594bab..5e6edae 100644 --- a/lib/gzip.js +++ b/lib/gzip.js @@ -51,6 +51,7 @@ exports = module.exports = function gzip(options) { var args = Array.prototype.slice.call(arguments, 0), write = defaults.write, end = defaults.end, + version = process.versions.node.split('.'), headers, key, accept, type, encoding, gzip, ua; if (args.length > 1) { headers = args.pop(); @@ -93,7 +94,7 @@ exports = module.exports = function gzip(options) { write.call(res, chunk); }); - gzip.addListener('exit', function(code) { + gzip.addListener(version[0] === 0 && version[1] < 7 ? "exit" : "close", function(code) { res.write = write; res.end = end; res.end(); diff --git a/test/helpers/index.js b/test/helpers/index.js index 5ad1982..7f352a6 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -90,14 +90,16 @@ exports.testMaxAge = function(app, url, headers, maxAge) { function gunzip(data, callback) { var process = spawn('gunzip', ['-c']), out = '', - err = ''; + err = '', + version = process.versions.node.split('.'); + process.stdout.on('data', function(data) { out += data; }); process.stderr.on('data', function(data) { err += data; }); - process.on('exit', function(code) { + process.on(version[0] === 0 && version[1] < 7 ? "exit" : "close", function(code) { if (callback) callback(err, out); }); process.stdin.end(data, 'binary');