lib/read.js
function readFile (archive, name, opts, cb) {
  if (typeof opts === 'function') {
    cb = opts
    opts = {}
  }

  return maybe(cb, async function () {
    opts = opts || {}
    if (typeof opts === 'string') {
      opts = { encoding: opts }
    }
    opts.encoding = toValidEncoding(opts.encoding)

    // check that it's a file
    const st = await stat(archive, name)
    if (!st.isFile()) {
      throw new NotAFileError()
    }

    // read the file
    return new Promise((resolve, reject) => {
      archive.readFile(name, opts, (err, data) => {
        if (err) reject(toBeakerError(err, 'readFile'))
        else resolve(data)
      })
    })
  })
}
function readFile (archive, name, opts, cb) {
  if (typeof opts === 'function') {
    cb = opts
    opts = {}
  }

  return maybe(cb, async function () {
    opts = opts || {}
    if (typeof opts === 'string') {
      opts = { encoding: opts }
    }
    opts.encoding = toValidEncoding(opts.encoding)

    // check that it's a file
    const st = await stat(archive, name)
    if (!st.isFile()) {
      throw new NotAFileError()
    }

    // read the file
    return new Promise((resolve, reject) => {
      archive.readFile(name, opts, (err, data) => {
        if (err) reject(toBeakerError(err, 'readFile'))
        else resolve(data)
      })
    })
  })
}
function readFile ( archive , name , opts , cb ) { if ( typeof opts === 'function' ) { cb = opts opts = { } } return maybe ( cb , async function ( ) { opts = opts || { } if ( typeof opts === 'string' ) { opts = { encoding : opts } } opts . encoding = toValidEncoding ( opts . encoding ) // check that it's a file const st = await stat ( archive , name ) if ( ! st . isFile ( ) ) { throw new NotAFileError ( ) } // read the file return new Promise ( ( resolve , reject ) => { archive . readFile ( name , opts , ( err , data ) => { if ( err ) reject ( toBeakerError ( err , 'readFile' ) ) else resolve ( data ) } ) } ) } ) }
helper to pull file data from an archive
helper to pull file data from an archive