"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/unpipe/index.js" (8 Mar 2017, 1118 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*!
    2  * unpipe
    3  * Copyright(c) 2015 Douglas Christopher Wilson
    4  * MIT Licensed
    5  */
    6 
    7 'use strict'
    8 
    9 /**
   10  * Module exports.
   11  * @public
   12  */
   13 
   14 module.exports = unpipe
   15 
   16 /**
   17  * Determine if there are Node.js pipe-like data listeners.
   18  * @private
   19  */
   20 
   21 function hasPipeDataListeners(stream) {
   22   var listeners = stream.listeners('data')
   23 
   24   for (var i = 0; i < listeners.length; i++) {
   25     if (listeners[i].name === 'ondata') {
   26       return true
   27     }
   28   }
   29 
   30   return false
   31 }
   32 
   33 /**
   34  * Unpipe a stream from all destinations.
   35  *
   36  * @param {object} stream
   37  * @public
   38  */
   39 
   40 function unpipe(stream) {
   41   if (!stream) {
   42     throw new TypeError('argument stream is required')
   43   }
   44 
   45   if (typeof stream.unpipe === 'function') {
   46     // new-style
   47     stream.unpipe()
   48     return
   49   }
   50 
   51   // Node.js 0.8 hack
   52   if (!hasPipeDataListeners(stream)) {
   53     return
   54   }
   55 
   56   var listener
   57   var listeners = stream.listeners('close')
   58 
   59   for (var i = 0; i < listeners.length; i++) {
   60     listener = listeners[i]
   61 
   62     if (listener.name !== 'cleanup' && listener.name !== 'onclose') {
   63       continue
   64     }
   65 
   66     // invoke the listener
   67     listener.call(stream)
   68   }
   69 }