Open an existing ZIP file for reading

@param string $file
@throws ArchiveIOException
355789
public function open($file)
    {
        $this->file = $file;
        $this->fh   = @fopen($this->file, 'rb');
        if (!$this->fh) {
            throw new ArchiveIOException('Could not open file for reading: '.$this->file);
        }
        $this->closed = false;
    }
680352
public function zipResourceFile($file, $resource)
    {
        if (!$this->zip->addFromString($file, json_encode($resource, JSON_UNESCAPED_SLASHES))) {
            throw new InternalServerErrorException("Failed to add $file to the Zip Archive.");
        }
    }
745772
public static void validateZip(File file) throws IOException {
    ZipInputStream zipInput = new ZipInputStream(new FileInputStream(file));
    ZipEntry zipEntry = zipInput.getNextEntry();

    while (zipEntry != null) {
      zipEntry = zipInput.getNextEntry();
    }

    try {
      if (zipInput != null) {
        zipInput.close();
      }
    } catch (IOException e) {
    }
  }
534018
public static function read($file)
    {
        $cwd = getcwd();
        $log = $cwd.'/producer.log';

        if (file_exists($file)) {
            file_put_contents($log, file_get_contents($file), FILE_APPEND);
        }
    }
1214844
public function load($file){
        $realPath = realpath($file);

        if (!$realPath || !file_exists($realPath)) {
            throw new FileNotFoundException($realPath);
        }

        $this->cookies = file_get_contents($realPath);     
    }
189295
public function add($file, $entry_name = null)
    {
        $result = $this->tar->addModify($file, '', dirname($file));
        if ($result === false) {
            throw new ArchiveException('Error adding file ' . $file);
        }

        return $this;
    }
288722
public function unzip($file, $path)
    {
        if (ends_with($file, '.zip')) {
            $this->message("Unzipping to {$file}");

            $this->unzipFile($file, $path);
        }
    }
1106152
public function getZip(string $id): Zip {

        if ( array_key_exists($id, $this->zip_archives) === false ) {
            throw new ZipException("Archive id $id not found");
        }
        return $this->zip_archives[$id];

    }
392080
public function load($file)
	{
		if(!$this->fs->exists($file))
		{
			throw new Exceptions\FileNotExists($file);
		}

		$this->file = $file;
		$this->info->load($file);
		$this->extension = $this->info->extension;
		$this->directory = $this->info->directory;
		$this->filename = $this->info->filename;

		$this->extracter->load($file, $this->extension)
						->extract();

		$this->params = $this->extracter->params();
	}
299270
public function create($file = '')
    {
        $this->file   = $file;
        $this->memory = '';
        $this->fh     = 0;

        if ($this->file) {
            $this->fh = @fopen($this->file, 'wb');

            if (!$this->fh) {
                throw new ArchiveIOException('Could not open file for writing: '.$this->file);
            }
        }
        $this->writeaccess = true;
        $this->closed      = false;
        $this->ctrl_dir    = array();
    }
313557
public function import($file)
    {
        $resource = $this->makeReadResource($file);

        // Maybe it will read and execute the resource statement by statement instead of reading all the resource at
        // once in the future, but it is not required yet.
        $sqlText = @stream_get_contents($resource);

        if ($sqlText === false) {
            $errorInfo = error_get_last();
            throw new FileException(sprintf(
                'Failed to read from the resource%s',
                $errorInfo ? ': '.$errorInfo['message'] : ''
            ));
        }

        @fclose($resource);
        $this->statements($sqlText);
    }
1296845
public function insertFile($file)
    {
        if ( ! $this->checkedIndexes) {
            $this->ensureIndexes();
        }

        $this->filesCollection->insertOne($file);
    }
1322230
public function archiveSingle($file, $desination = false)
    {
        if ($file == '') {
            throw new CompressException('__exception_compress_file_value_empty');
        }
        
        if (! file_exists($file)) {
            throw new CompressException('__exception_compress_file_not_exist');
        }
        
        if (! is_readable($file)) {
            throw new CompressException('__exception_compress_file_not_readable');
        }
        
        // work out path stuff
        $old_cwd = getcwd();
        $path = dirname($file);
        chdir($path);
        
        $name = $this->getArchiveName();
        $zip = $this->getArchiver();
        $zip->open($name, \ZipArchive::CREATE);
        if (file_exists($file)) {
            $zip->addFile(basename($file));
        }
        
        if ($zip->status != '0') {
            throw new CompressException('__exception_compression');
        }
        
        $zip->close();
        
        if (! $this->getKeepOriginal() && file_exists($file)) {
            unlink($file);
        }
        
        if ($desination) {
            $desination = realpath($desination) . DIRECTORY_SEPARATOR . $name;
            copy($name, $desination);
            unlink($name);
            
            $name = $desination;
        } else {
            $name = $path . DIRECTORY_SEPARATOR . $name;
        }
        
        // reset path
        chdir($old_cwd);
        
        return $name;
    }
725121
private function openImage($file)
        {

            // If $file isn't an array, we'll turn it into one.
            if (!is_array($file)) {
                $file_dimensions = getimagesize($file);
                $file = array(
                    'type'      => Inflector::lower($file_dimensions['mime']),
                    'tmp_name'  => $file
               );
            }

            $mime = $file['type'];
            $file_path = $file['tmp_name'];

            // Confirm that the file actually exists.
            if (!file_exists($file_path)) {
                throw new Exception('Could not find file: ' . $file_path . '. It doesn\'t seem to exist.');
            }

            switch ($mime) {
                case 'image/pjpeg': // IE6
                case File::mime('jpg'): $img = @imagecreatefromjpeg($file_path);  break;
                case File::mime('gif'): $img = @imagecreatefromgif($file_path);   break;
                case File::mime('png'): $img = @imagecreatefrompng($file_path);   break;
                default:                $img = false;                            break;
            }

            return $img;
        }
461051
public FileDigestOutputStream openFile(File file) throws IOException
   {
      MessageDigest md;
      try
      {
         md = MessageDigest.getInstance(digestAlgo);
      }
      catch (NoSuchAlgorithmException e)
      {
         LOG.error("Can't wriet using " + digestAlgo + " algorithm, " + e, e);
         throw new IOException(e.getMessage(), e);
      }

      return new FileDigestOutputStream(file, md);
   }
182865
public void instrumentZipFile(File zf) throws IOException {
        if (!zf.canRead() || !zf.canWrite()) {
            throw new IOException(zf + " can not be replaced");
        }

        File tempFile = File.createTempFile(zf.getName(), null, zf.getParentFile());
        if (tempFile.exists() && !tempFile.delete()) {
            throw new IOException("Unable to delete existing temp file " + tempFile.getName());
        }
        if (!zf.renameTo(tempFile)) {
            throw new IOException("Unable to rename existing jar " + zf);
        }

        ZipFile zipFile = new ZipFile(tempFile);
        FileOutputStream fos = new FileOutputStream(zf);
        ZipOutputStream zos = new ZipOutputStream(fos);
        boolean restoreZipFile = false;
        try {
            byte[] buffer = new byte[8192];
            Enumeration<? extends ZipEntry> e = zipFile.entries();
            while (e.hasMoreElements()) {
                ZipEntry oldEntry = e.nextElement();
                InputStream zis = zipFile.getInputStream(oldEntry);
                byte[] transformedClass = null;

                if (oldEntry.getName().endsWith(".class")) {
                    transformedClass = transform(zis);
                    if (transformedClass == null) {
                        zis = zipFile.getInputStream(oldEntry);
                    }
                }

                ZipEntry newEntry = new ZipEntry(oldEntry.getName());
                newEntry.setTime(transformedClass == null ? oldEntry.getTime() : System.currentTimeMillis());
                newEntry.setComment(oldEntry.getComment());
                newEntry.setExtra(oldEntry.getExtra());
                newEntry.setSize(transformedClass == null ? oldEntry.getSize() : transformedClass.length);

                if (newEntry.getSize() > Integer.MAX_VALUE) {
                    throw new IOException("ZipEntry too large: " + newEntry.getSize());
                }

                int entrySize = (int) newEntry.getSize();
                if (entrySize > buffer.length) {
                    buffer = new byte[entrySize];
                }

                if (transformedClass != null) {
                    System.arraycopy(transformedClass, 0, buffer, 0, entrySize);
                } else {
                    int totalBytesRead = 0;
                    while (totalBytesRead < entrySize) {
                        int bytesRead = zis.read(buffer, totalBytesRead, entrySize - totalBytesRead);
                        if (bytesRead == -1) {
                            throw new IOException("End of file encountered");
                        }
                        totalBytesRead += bytesRead;
                    }
                }

                zos.putNextEntry(newEntry);
                zos.write(buffer, 0, entrySize);
            }
        } catch (IOException ioe) {
            restoreZipFile = true;
            throw ioe;
        } catch (Throwable t) {
            restoreZipFile = true;
            IOException ioe = new IOException("Unexpected exception encountered during instrumentation");
            ioe.initCause(t);
            throw ioe;
        } finally {
            zos.close();
            fos.close();
            zipFile.close();
            if (restoreZipFile) {
                zf.delete();
                tempFile.renameTo(zf);
            } else {
                tempFile.delete();
            }
        }
    }
948036
public function load($file)
    {
        $loader = new PhpConfig();
        $templates = $loader->read($file);
        $this->add($templates);
    }