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 0c63dd7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"through2": "0.6.5"
},
"engines": {
"node": ">= 0.8.0"
"node": ">= 0.8"
},
"files": [
"HISTORY.md",
Expand Down

0 comments on commit 0c63dd7

Please sign in to comment.