1 // A reader for when we don't yet know what kind of thing
4 module.exports = ProxyReader
6 var Reader = require('./reader.js')
7 var getType = require('./get-type.js')
8 var inherits = require('inherits')
9 var fs = require('graceful-fs')
11 inherits(ProxyReader, Reader)
13 function ProxyReader (props) {
15 if (!(self instanceof ProxyReader)) {
16 throw new Error('ProxyReader must be called as constructor.')
23 Reader.call(self, props)
26 ProxyReader.prototype._stat = function () {
28 var props = self.props
29 // stat the thing to see what the proxy should be.
30 var stat = props.follow ? 'stat' : 'lstat'
32 fs[stat](props.path, function (er, current) {
37 type = getType(current)
41 props.type = self.type = type
44 self._addProxy(Reader(props, current))
48 ProxyReader.prototype._addProxy = function (proxy) {
50 if (self._proxyTarget) {
51 return self.error('proxy already set')
54 self._proxyTarget = proxy
69 ].forEach(function (ev) {
70 // console.error('~~ proxy event', ev, self.path)
71 proxy.on(ev, self.emit.bind(self, ev))
74 self.emit('proxy', proxy)
76 proxy.on('ready', function () {
77 // console.error("~~ proxy is ready!", self.path)
82 var calls = self._buffer
83 self._buffer.length = 0
84 calls.forEach(function (c) {
85 proxy[c[0]].apply(proxy, c[1])
89 ProxyReader.prototype.pause = function () {
90 return this._proxyTarget ? this._proxyTarget.pause() : false
93 ProxyReader.prototype.resume = function () {
94 return this._proxyTarget ? this._proxyTarget.resume() : false