lib/async.js
function read(description, options, callback) {
  var file = vfile(description)

  if (!callback && typeof options === 'function') {
    callback = options
    options = null
  }

  if (!callback) {
    return new Promise(executor)
  }

  executor(resolve, callback)

  function resolve(result) {
    callback(null, result)
  }

  function executor(resolve, reject) {
    var fp

    try {
      fp = path.resolve(file.cwd, file.path)
    } catch (error) {
      return reject(error)
    }

    fs.readFile(fp, options, done)

    function done(error, res) {
      if (error) {
        reject(error)
      } else {
        file.contents = res
        resolve(file)
      }
    }
  }
}
function read(description, options, callback) {
  var file = vfile(description)

  if (!callback && typeof options === 'function') {
    callback = options
    options = null
  }

  if (!callback) {
    return new Promise(executor)
  }

  executor(resolve, callback)

  function resolve(result) {
    callback(null, result)
  }

  function executor(resolve, reject) {
    var fp

    try {
      fp = path.resolve(file.cwd, file.path)
    } catch (error) {
      return reject(error)
    }

    fs.readFile(fp, options, done)

    function done(error, res) {
      if (error) {
        reject(error)
      } else {
        file.contents = res
        resolve(file)
      }
    }
  }
}
function read ( description , options , callback ) { var file = vfile ( description ) if ( ! callback && typeof options === 'function' ) { callback = options options = null } if ( ! callback ) { return new Promise ( executor ) } executor ( resolve , callback ) function resolve ( result ) { callback ( null , result ) } function executor ( resolve , reject ) { var fp try { fp = path . resolve ( file . cwd , file . path ) } catch ( error ) { return reject ( error ) } fs . readFile ( fp , options , done ) function done ( error , res ) { if ( error ) { reject ( error ) } else { file . contents = res resolve ( file ) } } } }
Create a virtual file and read it in, asynchronously.
Create a virtual file and read it in asynchronously .