Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ setTimeout(function() {
}, 1000)
```

If an `err` is returned in the callback it will have a `streamIndex` property indicating from which stream the error originated from.

You can use pump to pipe more than two streams together as well

``` js
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ var pump = function () {
var reading = i < streams.length - 1
var writing = i > 0
return destroyer(stream, reading, writing, function (err) {
if (!error) error = err
if (!error && err) {
error = err
error.streamIndex = i
}
if (err) destroys.forEach(call)
if (reading) return
destroys.forEach(call)
Expand Down
23 changes: 23 additions & 0 deletions test-node-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var pump = require('./index')

var rs = require('fs').createReadStream('/dev/random')
var ws = require('fs').createWriteStream('/dev/null')

var callbackCalled = false

var check = function (err) {
if (err && err.streamIndex === 0) {
console.log('test-node-error.js passes')
clearTimeout(timeout)
}
}

setTimeout(function () {
rs.destroy(new Error('premature close'))
}, 1000)

pump(rs, ws, check)

var timeout = setTimeout(function () {
throw new Error('timeout')
}, 5000)