|
|
@ -8,7 +8,7 @@ var assign = require('object-assign'); |
|
|
|
module.exports = function (url, opts, cb) { |
|
|
|
var redirectCount = 0; |
|
|
|
|
|
|
|
// Extract got options.
|
|
|
|
// extract own options
|
|
|
|
var encoding = opts.encoding; |
|
|
|
delete opts.encoding; |
|
|
|
|
|
|
@ -59,25 +59,20 @@ module.exports = function (url, opts, cb) { |
|
|
|
res.once('error', cb); |
|
|
|
|
|
|
|
var chunks = []; |
|
|
|
var n = 0; |
|
|
|
var len = 0; |
|
|
|
|
|
|
|
res.on('data', function (chunk) { |
|
|
|
// Add the new chunk to the list.
|
|
|
|
chunks.push(chunk); |
|
|
|
n += chunk.length; |
|
|
|
len += chunk.length; |
|
|
|
}); |
|
|
|
|
|
|
|
res.once('end', function () { |
|
|
|
// Concatenate all chunks into a single buffer.
|
|
|
|
var data = Buffer.concat(chunks, n); |
|
|
|
var data = Buffer.concat(chunks, len); |
|
|
|
|
|
|
|
// Unless the encoding has been explicitely set to `null`,
|
|
|
|
// convert the buffer to a string.
|
|
|
|
if (encoding !== null) { |
|
|
|
data = data.toString(encoding || 'utf8'); |
|
|
|
} |
|
|
|
|
|
|
|
// Return the result.
|
|
|
|
cb(null, data, res); |
|
|
|
}); |
|
|
|
}).once('error', cb); |
|
|
|