lib/writer.js
function Writer (props, current) {
  var self = this

  if (typeof props === 'string') {
    props = { path: props }
  }

  // polymorphism.
  // call fstream.Writer(dir) to get a DirWriter object, etc.
  var type = getType(props)
  var ClassType = Writer

  switch (type) {
    case 'Directory':
      ClassType = DirWriter
      break
    case 'File':
      ClassType = FileWriter
      break
    case 'Link':
    case 'SymbolicLink':
      ClassType = LinkWriter
      break
    case null:
    default:
      // Don't know yet what type to create, so we wrap in a proxy.
      ClassType = ProxyWriter
      break
  }

  if (!(self instanceof ClassType)) return new ClassType(props)

  // now get down to business.

  Abstract.call(self)

  if (!props.path) self.error('Must provide a path', null, true)

  // props is what we want to set.
  // set some convenience properties as well.
  self.type = props.type
  self.props = props
  self.depth = props.depth || 0
  self.clobber = props.clobber === false ? props.clobber : true
  self.parent = props.parent || null
  self.root = props.root || (props.parent && props.parent.root) || self

  self._path = self.path = path.resolve(props.path)
  if (process.platform === 'win32') {
    self.path = self._path = self.path.replace(/\?/g, '_')
    if (self._path.length >= 260) {
      self._swallowErrors = true
      self._path = '\\\\?\\' + self.path.replace(/\//g, '\\')
    }
  }
  self.basename = path.basename(props.path)
  self.dirname = path.dirname(props.path)
  self.linkpath = props.linkpath || null

  props.parent = props.root = null

  // console.error("\n\n\n%s setting size to", props.path, props.size)
  self.size = props.size

  if (typeof props.mode === 'string') {
    props.mode = parseInt(props.mode, 8)
  }

  self.readable = false
  self.writable = true

  // buffer until ready, or while handling another entry
  self._buffer = []
  self.ready = false

  self.filter = typeof props.filter === 'function' ? props.filter : null

  // start the ball rolling.
  // this checks what's there already, and then calls
  // self._create() to call the impl-specific creation stuff.
  self._stat(current)
}
function Writer (props, current) {
  var self = this

  if (typeof props === 'string') {
    props = { path: props }
  }

  // polymorphism.
  // call fstream.Writer(dir) to get a DirWriter object, etc.
  var type = getType(props)
  var ClassType = Writer

  switch (type) {
    case 'Directory':
      ClassType = DirWriter
      break
    case 'File':
      ClassType = FileWriter
      break
    case 'Link':
    case 'SymbolicLink':
      ClassType = LinkWriter
      break
    case null:
    default:
      // Don't know yet what type to create, so we wrap in a proxy.
      ClassType = ProxyWriter
      break
  }

  if (!(self instanceof ClassType)) return new ClassType(props)

  // now get down to business.

  Abstract.call(self)

  if (!props.path) self.error('Must provide a path', null, true)

  // props is what we want to set.
  // set some convenience properties as well.
  self.type = props.type
  self.props = props
  self.depth = props.depth || 0
  self.clobber = props.clobber === false ? props.clobber : true
  self.parent = props.parent || null
  self.root = props.root || (props.parent && props.parent.root) || self

  self._path = self.path = path.resolve(props.path)
  if (process.platform === 'win32') {
    self.path = self._path = self.path.replace(/\?/g, '_')
    if (self._path.length >= 260) {
      self._swallowErrors = true
      self._path = '\\\\?\\' + self.path.replace(/\//g, '\\')
    }
  }
  self.basename = path.basename(props.path)
  self.dirname = path.dirname(props.path)
  self.linkpath = props.linkpath || null

  props.parent = props.root = null

  // console.error("\n\n\n%s setting size to", props.path, props.size)
  self.size = props.size

  if (typeof props.mode === 'string') {
    props.mode = parseInt(props.mode, 8)
  }

  self.readable = false
  self.writable = true

  // buffer until ready, or while handling another entry
  self._buffer = []
  self.ready = false

  self.filter = typeof props.filter === 'function' ? props.filter : null

  // start the ball rolling.
  // this checks what's there already, and then calls
  // self._create() to call the impl-specific creation stuff.
  self._stat(current)
}
function Writer ( props , current ) { var self = this if ( typeof props === 'string' ) { props = { path : props } } // polymorphism. // call fstream.Writer(dir) to get a DirWriter object, etc. var type = getType ( props ) var ClassType = Writer switch ( type ) { case 'Directory' : ClassType = DirWriter break case 'File' : ClassType = FileWriter break case 'Link' : case 'SymbolicLink' : ClassType = LinkWriter break case null : default : // Don't know yet what type to create, so we wrap in a proxy. ClassType = ProxyWriter break } if ( ! ( self instanceof ClassType ) ) return new ClassType ( props ) // now get down to business. Abstract . call ( self ) if ( ! props . path ) self . error ( 'Must provide a path' , null , true ) // props is what we want to set. // set some convenience properties as well. self . type = props . type self . props = props self . depth = props . depth || 0 self . clobber = props . clobber === false ? props . clobber : true self . parent = props . parent || null self . root = props . root || ( props . parent && props . parent . root ) || self self . _path = self . path = path . resolve ( props . path ) if ( process . platform === 'win32' ) { self . path = self . _path = self . path . replace ( / \? / g , '_' ) if ( self . _path . length >= 260 ) { self . _swallowErrors = true self . _path = '\\\\?\\' + self . path . replace ( / \/ / g , '\\' ) } } self . basename = path . basename ( props . path ) self . dirname = path . dirname ( props . path ) self . linkpath = props . linkpath || null props . parent = props . root = null // console.error("\n\n\n%s setting size to", props.path, props.size) self . size = props . size if ( typeof props . mode === 'string' ) { props . mode = parseInt ( props . mode , 8 ) } self . readable = false self . writable = true // buffer until ready, or while handling another entry self . _buffer = [ ] self . ready = false self . filter = typeof props . filter === 'function' ? props . filter : null // start the ball rolling. // this checks what's there already, and then calls // self._create() to call the impl-specific creation stuff. self . _stat ( current ) }
props is the desired state.  current is optionally the current stat, provided here so that subclasses can avoid statting the target more than necessary.
props is the desired state . current is optionally the current stat provided here so that subclasses can avoid statting the target more than necessary .