diff --git a/index.js b/index.js index f8ce241c5..4aa5825f4 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,11 @@ const EventEmitter = require('events').EventEmitter; const http = require('http'); const https = require('https'); +const PassThrough = require('stream').PassThrough; +const duplexer2 = require('duplexer2'); const urlLib = require('url'); const querystring = require('querystring'); const objectAssign = require('object-assign'); -const duplexify = require('duplexify'); const isStream = require('is-stream'); const getStream = require('get-stream'); const timedOut = require('timed-out'); @@ -143,7 +144,9 @@ function asPromise(opts) { } function asStream(opts) { - const proxy = duplexify(); + const input = new PassThrough(); + const output = new PassThrough(); + const proxy = duplexer2(input, output); if (opts.json) { throw new Error('got can not be used as stream when options.json is used'); @@ -171,7 +174,7 @@ function asStream(opts) { } if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH') { - proxy.setWritable(req); + input.pipe(req); return; } @@ -181,7 +184,7 @@ function asStream(opts) { ee.on('response', res => { const statusCode = res.statusCode; - proxy.setReadable(res); + res.pipe(output); if (statusCode < 200 || statusCode > 299) { proxy.emit('error', new got.HTTPError(statusCode, opts), null, res); diff --git a/package.json b/package.json index e824904f9..c7ec760b6 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ ], "dependencies": { "create-error-class": "^2.0.0", - "duplexify": "^3.2.0", + "duplexer2": "floatdrop/duplexer2#f770b34", "get-stream": "^1.1.0", "is-plain-obj": "^1.0.0", "is-redirect": "^1.0.0",