Browse Source

code style

http2
Sindre Sorhus 11 years ago
parent
commit
1213b16a68
  1. 13
      index.js
  2. 5
      readme.md

13
index.js

@ -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);

5
readme.md

@ -49,9 +49,10 @@ Any of the [`http.request`](http://nodejs.org/api/http.html#http_http_request_op
##### options.encoding
Type: `string` or `null`
Type: `string`, `null`
Default: `'utf8'`
Encoding to be used on setEncoding of response data. If null, the body is returned as a Buffer.
Encoding to be used on `setEncoding` of the response data. If null, the body is returned as a Buffer.
##### callback(err, data, response)

Loading…
Cancel
Save