Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pfleidi/node-wwwdude
Browse files Browse the repository at this point in the history
Conflicts:
	package.json
  • Loading branch information
pfleidi committed Aug 15, 2011
2 parents f62f42f + 697a603 commit 06525b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/wwwdude/index.js
Expand Up @@ -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);
});
Expand Down
35 changes: 13 additions & 22 deletions lib/wwwdude/util.js
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
};
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -17,7 +17,8 @@
"url" : "http://github.com/pfleidi/node-wwwdude/raw/master/LICENSE"
}],
"dependencies" : {
"xml2js" : "= 0.1.9"
"xml2js" : "= 0.1.9",
"compress": "= 0.1.9"
},
"devDependencies": {
"expresso",
Expand Down

0 comments on commit 06525b3

Please sign in to comment.