Skip to content

Commit

Permalink
replace duplexify with patched duplexer2
Browse files Browse the repository at this point in the history
Closes #135
  • Loading branch information
floatdrop committed Dec 2, 2015
1 parent 4d6e03c commit 614ad28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions index.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -171,7 +174,7 @@ function asStream(opts) {
}

if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH') {
proxy.setWritable(req);
input.pipe(req);
return;
}

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down

0 comments on commit 614ad28

Please sign in to comment.