     entry.on 'end', ->
       filePathFound = true
       callback(null, Buffer.concat(contents).toString())
-  tarStream.on 'end', ->
-    unless filePathFound
-      callback(new Error("#{filePath} does not exist in the archive: #{archivePath}"))
 
 module.exports =
   list: (archivePath, callback) ->

        callback(null, Buffer.concat(contents).toString())
    else
      entry.autodrain()
  zipStream.on 'close', ->
    unless filePathFound
      callback(new Error("#{filePath} does not exist in the archive: #{archivePath}"))

readFileFromGzip = (archivePath, filePath, callback) ->
  if path.extname(path.basename(archivePath, '.gz')) isnt '.tar'
    callback(null, '')
    return

  zlib = require 'zlib'
  fileStream = createReadStream(archivePath, callback)
  gzipStream = fileStream.pipe(zlib.createGunzip())
  gzipStream.on 'error', (error) -> callback(error)
  readFileFromTarStream(gzipStream, archivePath, filePath, callback)

readFileFromTar = (archivePath, filePath, callback) ->
  fileStream = createReadStream(archivePath, callback)
  readFileFromTarStream(fileStream, archivePath, filePath, callback)

readFileFromTarStream = (inputStream, archivePath, filePath, callback) ->
  tar = require 'tar'
  tarStream = inputStream.pipe(tar.Parse())

  filePathFound = false
  tarStream.on 'error', (error) -> callback(error)
  tarStream.on 'entry', (entry) ->
    return if filePathFound
    return unless filePath is entry.props.path

  tarStream.on 'entry', (entry) -> paths.push(entry.props.path)
  tarStream.on 'end', -> callback(paths)

readFileFromZip = (archivePath, filePath, callback) ->
  unzip = require 'unzip'
  filePathFound = false
  fileStream = fs.createReadStream(archivePath)
  fileStream.on 'error', (error) -> callback(error) unless filePathFound
  fileStream.on 'end', ->
    unless filePathFound
      callback(new Error("#{filePath} does not exist in the archive: #{archivePath}"))
  zipStream = fileStream.pipe(unzip.Parse())
  zipStream.on 'error', (error) -> callback(error) unless filePathFound
  zipStream.on 'entry', (entry) ->
    if not filePathFound and filePath is entry.path
      contents = []
