Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[api] allow upload to be used to just get the response stream and ret…
…urn it to the callback
  • Loading branch information
jcrugzz committed Mar 4, 2014
1 parent d796b1c commit fa8d4aa
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions node.js/lib/client/client.js
Expand Up @@ -232,10 +232,14 @@ Client.prototype.request = function (options, callback) {
error.statusCode = statusCode;
error.result = result;
}

// Only add the response argument when people ask for it
if (callback.length === 3) return callback(error, result, res);
callback(error, result);
//
// If we don't pass a callback here, don't try and do anything fancy
//
if (callback) {
// Only add the response argument when people ask for it
if (callback.length === 3) return callback(error, result, res);
callback(error, result);
}
});
};

Expand Down Expand Up @@ -273,9 +277,12 @@ Client.prototype.upload = function (options, callback) {
options.body = false;

// Defer all the error handling to the request method
var req = self.request(options, callback);
var req = self.request(options);
if (!req) return;

req.on('error', callback);
req.on('response', callback.bind(null, null));

// Notify that we have started the upload procedure and give it a reference
// to the stat.
progress.emit('start', stat);
Expand Down

0 comments on commit fa8d4aa

Please sign in to comment.