Skip to content

Commit d013677

Browse files
committed
Merge pull request #153 from sindresorhus/duplexer2
Replace duplexify with duplexer2 and PassThrough streams
2 parents 43a6ea5 + 436600f commit d013677

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ var https = require('https');
55
var urlLib = require('url');
66
var querystring = require('querystring');
77
var objectAssign = require('object-assign');
8-
var duplexify = require('duplexify');
8+
var PassThrough = require('readable-stream').PassThrough;
9+
var duplexer2 = require('duplexer2');
910
var isStream = require('is-stream');
1011
var readAllStream = require('read-all-stream');
1112
var timedOut = require('timed-out');
@@ -140,7 +141,9 @@ function asPromise(opts) {
140141
}
141142

142143
function asStream(opts) {
143-
var proxy = duplexify();
144+
var input = new PassThrough();
145+
var output = new PassThrough();
146+
var proxy = duplexer2(input, output);
144147

145148
if (opts.json) {
146149
throw new Error('got can not be used as stream when options.json is used');
@@ -168,7 +171,7 @@ function asStream(opts) {
168171
}
169172

170173
if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH') {
171-
proxy.setWritable(req);
174+
input.pipe(req);
172175
return;
173176
}
174177

@@ -178,7 +181,7 @@ function asStream(opts) {
178181
ee.on('response', function (res) {
179182
var statusCode = res.statusCode;
180183

181-
proxy.setReadable(res);
184+
res.pipe(output);
182185

183186
if (statusCode < 200 || statusCode > 299) {
184187
proxy.emit('error', new got.HTTPError(statusCode, opts), null, res);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
],
4747
"dependencies": {
4848
"create-error-class": "^2.0.0",
49-
"duplexify": "^3.2.0",
49+
"duplexer2": "^0.1.4",
5050
"is-plain-obj": "^1.0.0",
5151
"is-redirect": "^1.0.0",
5252
"is-stream": "^1.0.0",
@@ -56,6 +56,7 @@
5656
"parse-json": "^2.1.0",
5757
"pinkie-promise": "^2.0.0",
5858
"read-all-stream": "^3.0.0",
59+
"readable-stream": "^2.0.5",
5960
"timed-out": "^2.0.0",
6061
"unzip-response": "^1.0.0",
6162
"url-parse-lax": "^1.0.0"

0 commit comments

Comments
 (0)