3 * Copyright(c) 2015 Douglas Christopher Wilson
14 module.exports = unpipe
17 * Determine if there are Node.js pipe-like data listeners.
21 function hasPipeDataListeners(stream) {
22 var listeners = stream.listeners('data')
24 for (var i = 0; i < listeners.length; i++) {
25 if (listeners[i].name === 'ondata') {
34 * Unpipe a stream from all destinations.
36 * @param {object} stream
40 function unpipe(stream) {
42 throw new TypeError('argument stream is required')
45 if (typeof stream.unpipe === 'function') {
52 if (!hasPipeDataListeners(stream)) {
57 var listeners = stream.listeners('close')
59 for (var i = 0; i < listeners.length; i++) {
60 listener = listeners[i]
62 if (listener.name !== 'cleanup' && listener.name !== 'onclose') {
66 // invoke the listener