Skip to content

Commit

Permalink
fix pipe(streams, fn) api. closes #51
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Jan 20, 2019
1 parent ba798ce commit bfa1972
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions index.js
Expand Up @@ -27,18 +27,19 @@ const defaultOpts = {
const pipe = (...streams) => {
let opts, cb

if (Array.isArray(streams[0])) {
streams = streams[0]
}
if (typeof streams[streams.length - 1] === 'function') {
cb = streams.pop()
}
if (
typeof streams[streams.length - 1] === 'object' &&
!Array.isArray(streams[streams.length - 1]) &&
typeof streams[streams.length - 1].pipe !== 'function'
) {
opts = streams.pop()
}
if (Array.isArray(streams[0])) {
streams = streams[0]
}

const first = streams[0]
const last = streams[streams.length - 1]
Expand Down
17 changes: 17 additions & 0 deletions test/multipipe.js
Expand Up @@ -212,3 +212,20 @@ describe('pipe(a, b, c, fn)', () => {
c.emit('finish', true)
})
})

describe('pipe([a, b, c], fn)', () => {
it('should call on finish', done => {
let finished = false
const a = Readable()
const b = Transform()
const c = Writable(function () {
finished = true
})

pipe([a, b, c], err => {
assert(!err)
assert(finished)
done()
})
})
})

0 comments on commit bfa1972

Please sign in to comment.