From 9d7ec4e07d86fa02a3df05446b9ad7d8a040ecdc Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Thu, 8 Sep 2016 17:02:56 +0200 Subject: [PATCH] fix: readable streams are resumed when piped Ref https://github.com/nodejs/node/blob/master/lib/_stream_readable.js\#L606-L610 --- index.js | 14 ++++++++++++-- test/pipe.js | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/pipe.js diff --git a/index.js b/index.js index 8a59e43..fe23da2 100644 --- a/index.js +++ b/index.js @@ -81,7 +81,18 @@ function duplex (reader, read) { next(drain) } - if(read) s.sink(read) + if(read) { + s.sink(read) + + var pipe = s.pipe.bind(s) + s.pipe = function (dest, opts) { + var res = pipe(dest, opts) + + if(s.paused) s.resume() + + return res + } + } function drain () { waiting = false @@ -134,4 +145,3 @@ function duplex (reader, read) { return s } - diff --git a/test/pipe.js b/test/pipe.js new file mode 100644 index 0000000..0944fd5 --- /dev/null +++ b/test/pipe.js @@ -0,0 +1,18 @@ +var pull = require('pull-stream') +var defer = require('pull-defer') +var Readable = require('stream').Readable +var duplex = require('../') + +var test = require('tape') + +test('pipe - resume', function (t) { + + var s = duplex(null, pull(pull.infinite(), pull.take(10))) + s.pause() + + s.pipe(duplex(pull.collect(function (err, values) { + t.equal(values.length, 10) + t.end() + }), null)) + +})