index.js
function checkIfExists () {
    // Create after we check for pre-sleep .dat stuff
    var createAfterValid = (createIfMissing && !errorIfExists)

    var missingError = new Error('Dat storage does not exist.')
    missingError.name = 'MissingError'
    var existsError = new Error('Dat storage already exists.')
    existsError.name = 'ExistsError'
    var oldError = new Error('Dat folder contains incompatible metadata. Please remove your metadata (rm -rf .dat).')
    oldError.name = 'IncompatibleError'

    fs.readdir(path.join(opts.dir, '.dat'), function (err, files) {
      // TODO: omg please make this less confusing.
      var noDat = !!(err || !files.length)
      hasDat = !noDat
      var validSleep = (files && files.length && files.indexOf('metadata.key') > -1)
      var badDat = !(noDat || validSleep)

      if ((noDat || validSleep) && createAfterValid) return create()
      else if (badDat) return cb(oldError)

      if (err && !createIfMissing) return cb(missingError)
      else if (!err && errorIfExists) return cb(existsError)

      return create()
    })
  }
function checkIfExists () {
    // Create after we check for pre-sleep .dat stuff
    var createAfterValid = (createIfMissing && !errorIfExists)

    var missingError = new Error('Dat storage does not exist.')
    missingError.name = 'MissingError'
    var existsError = new Error('Dat storage already exists.')
    existsError.name = 'ExistsError'
    var oldError = new Error('Dat folder contains incompatible metadata. Please remove your metadata (rm -rf .dat).')
    oldError.name = 'IncompatibleError'

    fs.readdir(path.join(opts.dir, '.dat'), function (err, files) {
      // TODO: omg please make this less confusing.
      var noDat = !!(err || !files.length)
      hasDat = !noDat
      var validSleep = (files && files.length && files.indexOf('metadata.key') > -1)
      var badDat = !(noDat || validSleep)

      if ((noDat || validSleep) && createAfterValid) return create()
      else if (badDat) return cb(oldError)

      if (err && !createIfMissing) return cb(missingError)
      else if (!err && errorIfExists) return cb(existsError)

      return create()
    })
  }
function checkIfExists ( ) { // Create after we check for pre-sleep .dat stuff var createAfterValid = ( createIfMissing && ! errorIfExists ) var missingError = new Error ( 'Dat storage does not exist.' ) missingError . name = 'MissingError' var existsError = new Error ( 'Dat storage already exists.' ) existsError . name = 'ExistsError' var oldError = new Error ( 'Dat folder contains incompatible metadata. Please remove your metadata (rm -rf .dat).' ) oldError . name = 'IncompatibleError' fs . readdir ( path . join ( opts . dir , '.dat' ) , function ( err , files ) { // TODO: omg please make this less confusing. var noDat = ! ! ( err || ! files . length ) hasDat = ! noDat var validSleep = ( files && files . length && files . indexOf ( 'metadata.key' ) > - 1 ) var badDat = ! ( noDat || validSleep ) if ( ( noDat || validSleep ) && createAfterValid ) return create ( ) else if ( badDat ) return cb ( oldError ) if ( err && ! createIfMissing ) return cb ( missingError ) else if ( ! err && errorIfExists ) return cb ( existsError ) return create ( ) } ) }
Check if archive storage folder exists.
@private
Check if archive storage folder exists .