Comparing version 1.0.1 to 1.1.0
26
index.js
@@ -11,2 +11,6 @@ 'use strict'; | ||
// extract own options | ||
var encoding = opts.encoding; | ||
delete opts.encoding; | ||
var get = function (url, opts, cb) { | ||
@@ -31,4 +35,2 @@ if (typeof opts === 'function') { | ||
fn.get(arg, function (res) { | ||
var ret = ''; | ||
// redirect | ||
@@ -59,12 +61,20 @@ if (res.statusCode < 400 && res.statusCode >= 300 && res.headers.location) { | ||
res.setEncoding('utf8'); | ||
res.once('error', cb); | ||
res.on('data', function (data) { | ||
ret += data; | ||
var chunks = []; | ||
var len = 0; | ||
res.on('data', function (chunk) { | ||
chunks.push(chunk); | ||
len += chunk.length; | ||
}); | ||
res.once('error', cb); | ||
res.once('end', function () { | ||
var data = Buffer.concat(chunks, len); | ||
res.once('end', function () { | ||
cb(null, ret, res); | ||
if (encoding !== null) { | ||
data = data.toString(encoding || 'utf8'); | ||
} | ||
cb(null, data, res); | ||
}); | ||
@@ -71,0 +81,0 @@ }).once('error', cb); |
{ | ||
"name": "got", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Simplified HTTP/HTTPS requests", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -50,2 +50,9 @@ # got [![Build Status](https://travis-ci.org/sindresorhus/got.svg?branch=master)](https://travis-ci.org/sindresorhus/got) | ||
##### options.encoding | ||
Type: `string`, `null` | ||
Default: `'utf8'` | ||
Encoding to be used on `setEncoding` of the response data. If null, the body is returned as a Buffer. | ||
##### callback(err, data, response) | ||
@@ -52,0 +59,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3713
64
71