Browse Source

replace read-all-stream with get-stream

Closes #132
http2
Vsevolod Strukchinsky 9 years ago
parent
commit
9378d92120
  1. 42
      index.js
  2. 4
      package.json

42
index.js

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

4
package.json

@ -47,6 +47,7 @@
"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",
@ -54,7 +55,6 @@
"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"
@ -71,7 +71,7 @@
"xo": "*"
},
"xo": {
"esnext": true,
"esnext": false,
"ignores": [
"test/**"
]

Loading…
Cancel
Save