Skip to content

Commit

Permalink
fix: readable streams are resumed when piped
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Sep 8, 2016
1 parent 9b314b6 commit 9d7ec4e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -134,4 +145,3 @@ function duplex (reader, read) {

return s
}

18 changes: 18 additions & 0 deletions test/pipe.js
Original file line number Diff line number Diff line change
@@ -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))

})

0 comments on commit 9d7ec4e

Please sign in to comment.