Skip to content

Commit

Permalink
Fix a false-positive when unpiping in Node.js 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed May 11, 2015
1 parent 74cca15 commit 2d5ec4f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased
==========

* Fix a false-positive when unpiping in Node.js 0.8

2.0.0 / 2015-05-08
==================

Expand Down
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ function halt(stream) {
}
}

/**
* Determine if there are Node.js pipe-like data listeners.
*/

/* istanbul ignore next: implementation differs between versions */
function hasPipeDataListeners(stream) {
var listeners = stream.listeners('data')

for (var i = 0; i < listeners.length; i++) {
if (listeners[i].name === 'ondata') {
return true
}
}

return false
}

/**
* Make a serializable error object.
*
Expand Down Expand Up @@ -307,6 +324,10 @@ function unpipe(stream) {
}

// Node.js 0.8 hack
if (!hasPipeDataListeners(stream)) {
return
}

var listener
var listeners = stream.listeners('close')

Expand Down

0 comments on commit 2d5ec4f

Please sign in to comment.