Sha256: a9c337f6d5c21ec2384366b3c9f96e4d44703b1a278802f04c60bc158d0ea093

Contents?: true

Size: 1.92 KB

Versions: 11

Compression:

Stored size: 1.92 KB

Contents

// A reader for when we don't yet know what kind of thing
// the thing is.

module.exports = ProxyReader

var Reader = require("./reader.js")
  , getType = require("./get-type.js")
  , inherits = require("inherits")
  , fs = require("graceful-fs")

inherits(ProxyReader, Reader)

function ProxyReader (props) {
  var me = this
  if (!(me instanceof ProxyReader)) throw new Error(
    "ProxyReader must be called as constructor.")

  me.props = props
  me._buffer = []
  me.ready = false

  Reader.call(me, props)
}

ProxyReader.prototype._stat = function () {
  var me = this
    , props = me.props
    // stat the thing to see what the proxy should be.
    , stat = props.follow ? "stat" : "lstat"

  fs[stat](props.path, function (er, current) {
    var type
    if (er || !current) {
      type = "File"
    } else {
      type = getType(current)
    }

    props[type] = true
    props.type = me.type = type

    me._old = current
    me._addProxy(Reader(props, current))
  })
}

ProxyReader.prototype._addProxy = function (proxy) {
  var me = this
  if (me._proxyTarget) {
    return me.error("proxy already set")
  }

  me._proxyTarget = proxy
  proxy._proxy = me

  ; [ "error"
    , "data"
    , "end"
    , "close"
    , "linkpath"
    , "entry"
    , "entryEnd"
    , "child"
    , "childEnd"
    , "warn"
    , "stat"
    ].forEach(function (ev) {
      // console.error("~~ proxy event", ev, me.path)
      proxy.on(ev, me.emit.bind(me, ev))
    })

  me.emit("proxy", proxy)

  proxy.on("ready", function () {
    // console.error("~~ proxy is ready!", me.path)
    me.ready = true
    me.emit("ready")
  })

  var calls = me._buffer
  me._buffer.length = 0
  calls.forEach(function (c) {
    proxy[c[0]].apply(proxy, c[1])
  })
}

ProxyReader.prototype.pause = function () {
  return this._proxyTarget ? this._proxyTarget.pause() : false
}

ProxyReader.prototype.resume = function () {
  return this._proxyTarget ? this._proxyTarget.resume() : false
}

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
es6_tilt-0.1.2 test/dummy/app/assets/javascripts/node_modules/fsevents/node_modules/node-pre-gyp/node_modules/tar-pack/node_modules/fstream/lib/proxy-reader.js
es6_tilt-0.1.1 test/dummy/app/assets/javascripts/node_modules/fsevents/node_modules/node-pre-gyp/node_modules/tar-pack/node_modules/fstream/lib/proxy-reader.js
es6_tilt-0.1.0 test/dummy/app/assets/javascripts/node_modules/fsevents/node_modules/node-pre-gyp/node_modules/tar-pack/node_modules/fstream/lib/proxy-reader.js
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/fstream/lib/proxy-reader.js
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/fstream/lib/proxy-reader.js
entangled-0.0.14 spec/dummy/public/node_modules/bower/node_modules/fstream/lib/proxy-reader.js
entangled-0.0.13 spec/dummy/public/node_modules/bower/node_modules/fstream/lib/proxy-reader.js
entangled-0.0.12 spec/dummy/public/node_modules/bower/node_modules/fstream/lib/proxy-reader.js
entangled-0.0.11 spec/dummy/public/node_modules/bower/node_modules/fstream/lib/proxy-reader.js
entangled-0.0.10 spec/dummy/public/node_modules/bower/node_modules/fstream/lib/proxy-reader.js
embeditor-rails-2.0.0.beta lib/node_modules/npm/node_modules/fstream/lib/proxy-reader.js