"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/fstream/lib/proxy-reader.js" (7 Feb 2017, 2004 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 // A reader for when we don't yet know what kind of thing
    2 // the thing is.
    3 
    4 module.exports = ProxyReader
    5 
    6 var Reader = require('./reader.js')
    7 var getType = require('./get-type.js')
    8 var inherits = require('inherits')
    9 var fs = require('graceful-fs')
   10 
   11 inherits(ProxyReader, Reader)
   12 
   13 function ProxyReader (props) {
   14   var self = this
   15   if (!(self instanceof ProxyReader)) {
   16     throw new Error('ProxyReader must be called as constructor.')
   17   }
   18 
   19   self.props = props
   20   self._buffer = []
   21   self.ready = false
   22 
   23   Reader.call(self, props)
   24 }
   25 
   26 ProxyReader.prototype._stat = function () {
   27   var self = this
   28   var props = self.props
   29   // stat the thing to see what the proxy should be.
   30   var stat = props.follow ? 'stat' : 'lstat'
   31 
   32   fs[stat](props.path, function (er, current) {
   33     var type
   34     if (er || !current) {
   35       type = 'File'
   36     } else {
   37       type = getType(current)
   38     }
   39 
   40     props[type] = true
   41     props.type = self.type = type
   42 
   43     self._old = current
   44     self._addProxy(Reader(props, current))
   45   })
   46 }
   47 
   48 ProxyReader.prototype._addProxy = function (proxy) {
   49   var self = this
   50   if (self._proxyTarget) {
   51     return self.error('proxy already set')
   52   }
   53 
   54   self._proxyTarget = proxy
   55   proxy._proxy = self
   56 
   57   ;[
   58     'error',
   59     'data',
   60     'end',
   61     'close',
   62     'linkpath',
   63     'entry',
   64     'entryEnd',
   65     'child',
   66     'childEnd',
   67     'warn',
   68     'stat'
   69   ].forEach(function (ev) {
   70     // console.error('~~ proxy event', ev, self.path)
   71     proxy.on(ev, self.emit.bind(self, ev))
   72   })
   73 
   74   self.emit('proxy', proxy)
   75 
   76   proxy.on('ready', function () {
   77     // console.error("~~ proxy is ready!", self.path)
   78     self.ready = true
   79     self.emit('ready')
   80   })
   81 
   82   var calls = self._buffer
   83   self._buffer.length = 0
   84   calls.forEach(function (c) {
   85     proxy[c[0]].apply(proxy, c[1])
   86   })
   87 }
   88 
   89 ProxyReader.prototype.pause = function () {
   90   return this._proxyTarget ? this._proxyTarget.pause() : false
   91 }
   92 
   93 ProxyReader.prototype.resume = function () {
   94   return this._proxyTarget ? this._proxyTarget.resume() : false
   95 }