diff --git a/libs/s3-utils.js b/libs/s3-utils.js index bc90056..630597b 100644 --- a/libs/s3-utils.js +++ b/libs/s3-utils.js @@ -69,14 +69,19 @@ return deferred.reject(err); }); req.on("response", function(res) { + var data; + data = ''; if (res.statusCode === 404) { console.warn("No object found at " + path + "."); return deferred.resolve({}); } else if (res.statusCode === 200) { - return res.on('data', function(chunk) { + res.on('data', function(chunk) { + return data += chunk; + }); + return res.on('end', function() { var e, obj; try { - obj = JSON.parse(chunk); + obj = JSON.parse(data); return deferred.resolve(obj); } catch (_error) { e = _error; diff --git a/src/s3-utils.coffee b/src/s3-utils.coffee index aa4ac19..e30552a 100644 --- a/src/s3-utils.coffee +++ b/src/s3-utils.coffee @@ -48,7 +48,7 @@ exports.downloadObject = (path, client, timeoutMillis = 1000*30) => deferred.reject err req.on "response", (res) => - data = undefined + data = '' if res.statusCode is 404 console.warn "No object found at #{path}." deferred.resolve {}