Permalink
Browse files

replaceing the way gzip content encoding is handled - using the compr…

…ess library to inflate gzip encoded data instead of spawning a child process
  • Loading branch information...
1 parent cbe9e27 commit d2d6d3b9632dbbac302f6051b25eeda335827bbc @lalitkapoor lalitkapoor committed Aug 12, 2011
Showing with 16 additions and 24 deletions.
  1. +1 −1 lib/wwwdude/index.js
  2. +13 −22 lib/wwwdude/util.js
  3. +2 −1 package.json
View
2 lib/wwwdude/index.js
@@ -186,7 +186,7 @@ var createClient = exports.createClient = function createClient(clientOptions) {
response.on('end', function () {
if (useGzip) {
- Util.decodeGzip(body, encoding, function (err, data) {
+ Util.decodeGzip(body, function (err, data) {
response.rawData = data;
_handleResponse(response);
});
View
35 lib/wwwdude/util.js
@@ -11,7 +11,7 @@
/* Module dependencies */
var Url = require('url');
-var Child_process = require('child_process');
+var Compress = require('compress');
/**
* lookup table for all HTTP status codes
@@ -129,32 +129,23 @@ exports.parseUrl = function parseUrl(url) {
};
/**
- * Decode gzip content with an external gunzip command
+ * Decode gzip content
* call request._handleResponse() when ready
*
* @param {Object} data
* @param {Function} callback
* @return {undefined}
* @api public
*/
-exports.decodeGzip = function decodeGzip(data, encoding, callback) {
+exports.decodeGzip = function decodeGzip(data, callback) {
var body = '';
- var gunzip = Child_process.spawn('gunzip', ['-9']);
-
- gunzip.stdin.write(data, 'binary');
- gunzip.stdin.end();
-
- gunzip.stdout.setEncoding(encoding);
-
- gunzip.stdout.on('data', function (data) {
- body += data;
- });
-
- gunzip.on('exit', function (code) {
- if (code === 0) {
- callback(null, body);
- } else {
- callback(new Error('Process gzip returned with error code: ' + code));
- }
- });
- };
+ var gunzip = new Compress.Gunzip;
+ gunzip.init();
+
+ try{
+ body += gunzip.inflate(data.toString('binary'), 'binary') + gunzip.end();
+ callback(null, body);
+ } catch(e){
+ callback(e);
+ }
+};
View
3 package.json
@@ -17,7 +17,8 @@
"url" : "http://github.com/pfleidi/node-wwwdude/raw/master/LICENSE"
}],
"dependencies" : {
- "xml2js-expat" : "= 0.2.0"
+ "xml2js-expat" : "= 0.2.0",
+ "compress": "=0.1.9"
},
"engines" : { "node": ">= 0.2.0" },
"main" : "index"

0 comments on commit d2d6d3b

Please sign in to comment.