Skip to content

Commit

Permalink
replace read-all-stream with get-stream
Browse files Browse the repository at this point in the history
Closes #132
  • Loading branch information
floatdrop committed Dec 2, 2015
1 parent 3fcf503 commit f0c9843
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
42 changes: 21 additions & 21 deletions index.js
Expand Up @@ -6,7 +6,7 @@ const querystring = require('querystring');
const objectAssign = require('object-assign');
const duplexify = require('duplexify');
const isStream = require('is-stream');
const readAllStream = require('read-all-stream');
const getStream = require('get-stream');
const timedOut = require('timed-out');
const urlParseLax = require('url-parse-lax');
const lowercaseKeys = require('lowercase-keys');
Expand Down Expand Up @@ -87,31 +87,31 @@ function asCallback(opts, cb) {
req.end(opts.body);
});

ee.on('response', res =>
readAllStream(res, opts.encoding, (err, data) => {
var statusCode = res.statusCode;
ee.on('response', res => {
var stream = opts.encoding === null ? getStream.buffer(res) : getStream(res, opts);

if (err) {
cb(new got.ReadError(err, opts), null, res);
return;
}
stream
.then(data => {
var err;
var statusCode = res.statusCode;

if (statusCode < 200 || statusCode > 299) {
err = new got.HTTPError(statusCode, opts);
}
if (statusCode < 200 || statusCode > 299) {
err = new got.HTTPError(statusCode, opts);
}

if (opts.json && statusCode !== 204) {
try {
data = parseJson(data);
} catch (e) {
e.fileName = urlLib.format(opts);
err = new got.ParseError(e, opts);
if (opts.json && statusCode !== 204) {
try {
data = parseJson(data);
} catch (e) {
e.fileName = urlLib.format(opts);
err = new got.ParseError(e, opts);
}
}
}

cb(err, data, res);
})
);
cb(err, data, res);
})
.catch(err => cb(new got.ReadError(err, opts), null, res));
});

ee.on('error', cb);
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -47,14 +47,14 @@
"dependencies": {
"create-error-class": "^2.0.0",
"duplexify": "^3.2.0",
"get-stream": "^1.1.0",
"is-plain-obj": "^1.0.0",
"is-redirect": "^1.0.0",
"is-stream": "^1.0.0",
"lowercase-keys": "^1.0.0",
"node-status-codes": "^1.0.0",
"object-assign": "^4.0.1",
"parse-json": "^2.1.0",
"read-all-stream": "^3.0.0",
"timed-out": "^2.0.0",
"unzip-response": "^1.0.0",
"url-parse-lax": "^1.0.0"
Expand All @@ -71,7 +71,7 @@
"xo": "*"
},
"xo": {
"esnext": true,
"esnext": false,
"ignores": [
"test/**"
]
Expand Down

0 comments on commit f0c9843

Please sign in to comment.