Unzip a file into a directory using the ZipArchive class.

@param string $file The absolute path to a zip file.
@param string $destination The absolute path to the directory to unzip to file into.
@return bool Success/Failure.
769033
public static function unzip_using_ziparchive($file, $destination) {
		$za = new \ZipArchive;
		$zares = $za->open($file);
		if ($zares === true) {
			$za->extractTo($destination);
			$za->close();
			return true;
		} else {
			return false;
		}
	}
1135765
public function extract($name, $destination = null)
    {
        $file = $this->findOne($name);

        if (! $file || ! $file->write($destination)) {
            return false;
        }

        return (bool) $this->collection->remove(['_id' => $file->file['_id']]);
    }
1103628
protected function unzipModule(UploadedFile $file)
    {
        $extractPath = false;
        $zip = new ZipArchiver(true);
        if (!$zip->open($file->getRealPath())) {
            throw new \Exception("unable to open zipfile");
        }

        $extractPath = $this->tempdir();

        if ($extractPath !== false) {
            if ($zip->extract($extractPath) === false) {
                $extractPath = false;
            }
        }

        $zip->close();

        return $extractPath;
    }
1193077
function package($destination, $method='tgz')
    {
        $method = strtolower($method);
        if ($method != 'zip' && $method != 'tgz') {
            throw new BagItException("Invalid compression method: '$method'.");
        }

        if (substr_compare($destination, ".$method", -4, 4, true) != 0) {
            $destination = "$destination.$method";
        }

        BagIt_compressBag(
            $this->bagDirectory,
            $destination,
            $method
        );
    }
21787
def unzip(source_file, destination_dir):
    
    with zipfile.ZipFile(source_file) as zf:
        zf.extractall(destination_dir)
370060
public function extractArchive($archive, $destination)
    {
        if (!file_exists($archive)) {
            throw new \InvalidArgumentException("Archive not found: $archive");
        }
        if (!file_exists($destination) && !mkdir($destination, 0755, true)) {
            throw new \InvalidArgumentException("Could not create destination directory: $destination");
        }
        $tar = $this->getTarExecutable();
        $destination = $this->fixTarPath($destination);
        $archive = $this->fixTarPath($archive);
        $this->shell->execute([$tar, '-xzp', '-C' . $destination, '-f' . $archive], null, true);
    }
593804
public function rmFile($file)
    {

        if (!is_file($file)) {
            $this->errorMsg = "this is not a file";
            return false;
        }
        if (unlink($file)) {
            return true;
        } else {
            $this->errorMsg = "fail to remove the file!";
            return false;
        }
    }
947466
public function extract($archive, $destination)
	{
		$this->data = null;

		if (!isset($this->options['use_streams']) || $this->options['use_streams'] == false)
		{
			$this->data = file_get_contents($archive);

			if (!$this->data)
			{
				throw new \RuntimeException('Unable to read archive');
			}

			$position = $this->getFilePosition();
			$buffer   = gzinflate(substr($this->data, $position, \strlen($this->data) - $position));

			if (empty($buffer))
			{
				throw new \RuntimeException('Unable to decompress data');
			}

			if (!File::write($destination, $buffer))
			{
				throw new \RuntimeException('Unable to write archive to file ' . $destination);
			}
		}
		else
		{
			// New style! streams!
			$input = Stream::getStream();

			// Use gz
			$input->set('processingmethod', 'gz');

			if (!$input->open($archive))
			{
				throw new \RuntimeException('Unable to read archive');
			}

			$output = Stream::getStream();

			if (!$output->open($destination, 'w'))
			{
				$input->close();

				throw new \RuntimeException('Unable to open file "' . $destination . '" for writing');
			}

			do
			{
				$this->data = $input->read($input->get('chunksize', 8196));

				if ($this->data)
				{
					if (!$output->write($this->data))
					{
						$input->close();

						throw new \RuntimeException('Unable to write archive to file ' . $destination);
					}
				}
			}
			while ($this->data);

			$output->close();
			$input->close();
		}

		return true;
	}
687609
protected function copyDirectory($directory, $destination)
    {
        // Preference is to overwrite existing files
        if ($this->overwrite) {
            return File::copyDirectory($directory, $destination);
        }

        if (!File::isDirectory($directory)) {
            return false;
        }

        $options = FilesystemIterator::SKIP_DOTS;

        if (!File::isDirectory($destination)) {
            File::makeDirectory($destination, 0777, true);
        }

        $items = new FilesystemIterator($directory, $options);

        foreach ($items as $item) {
            $target = $destination.'/'.$item->getBasename();

            if ($item->isDir()) {
                $path = $item->getPathname();

                if (!$this->copyDirectory($path, $target)) {
                    return false;
                }
            }
            else {
                // Do not overwrite existing files
                if (File::isFile($target)) {
                    continue;
                }

                if (!File::copy($item->getPathname(), $target)) {
                    return false;
                }
            }
        }

        return true;
    }
1260935
public function extractTo($destination, $entities = null)
    {
        if ($entities) {
            return $this->zipArchive->extractTo($destination, $entities);
        } else {
            return $this->zipArchive->extractTo($destination);
        }
    }
679623
public void unzipArchive(String file, File outputDir)
      throws IOException {

    try (ZipFile zipFile = new ZipFile(file)) {

      final Enumeration<? extends ZipEntry> entries = zipFile.entries();
      while (entries.hasMoreElements()) {
        final ZipEntry entry = entries.nextElement();
        final File entryDestination = new File(outputDir, entry.getName());
        if (!org.apache.gobblin.util.FileUtils.isSubPath(outputDir, entryDestination)) {
          throw new IOException(String.format("Extracted file: %s is trying to write outside of output directory: %s",
              entryDestination, outputDir));
        }

        if (entry.isDirectory()) {
          // If entry is directory, create directory
          if (!entryDestination.mkdirs() && !entryDestination.exists()) {
            throw new IOException("Could not create directory: " + entryDestination
                + " while un-archiving zip: " + file);
          }
        } else {
          // Create parent dirs if required
          if (!entryDestination.getParentFile().mkdirs() && !entryDestination.getParentFile().exists()) {
            throw new IOException("Could not create parent directory for: " + entryDestination
                + " while un-archiving zip: " + file);
          }

          // Extract and save the conf file
          InputStream in = null;
          OutputStream out = null;
          try {
            in = zipFile.getInputStream(entry);
            out = new FileOutputStream(entryDestination);
            IOUtils.copy(in, out);
          } finally {
            if (null != in)
              IOUtils.closeQuietly(in);
            if (null != out)
              IOUtils.closeQuietly(out);
          }
        }
      }
    }
  }
652742
public function copyTo($destination)
    {
        foreach ($this as $source_path => $asset_path) {
            if (!is_readable($source_path)) {
                if ($this->logger) {
                    $this->logger->error('Asset "' . $source_path . '" could not be found or is not readable');
                }

                continue;
            }

            $destination_path = $destination . '/' . $asset_path;
            if (!file_exists(dirname($destination_path))) {
                mkdir(dirname($destination_path), 0777, true);
            }

            copy($source_path, $destination_path);
        }
    }
719198
public function zip($file)
    {
        if (!function_exists('zip_open')) {
            return false;
        }

        $zip = zip_open($file);

        if (is_resource($zip)) {
            zip_close($zip);
            return true;
        }

        return false;
    }
94899
protected function _unzip($file)
    {
        include_once Plugin::classPath('Installer') . 'Lib/pclzip.lib.php';
        $File = new File($file);
        $to = normalizePath($File->folder()->pwd() . '/' . $File->name() . '_unzip/');

        if (is_readable($to)) {
            $folder = new Folder($to);
            $folder->delete();
        } else {
            $folder = new Folder($to, true);
        }

        $PclZip = new \PclZip($file);
        $PclZip->delete(PCLZIP_OPT_BY_EREG, '/__MACOSX/');
        $PclZip->delete(PCLZIP_OPT_BY_EREG, '/\.DS_Store$/');

        if ($PclZip->extract(PCLZIP_OPT_PATH, $to)) {
            list($directories, $files) = $folder->read(false, false, true);
            if (count($directories) === 1 && empty($files)) {
                $container = new Folder($directories[0]);
                $container->move(['to' => $to]);
            }

            $this->_workingDir = $to;

            return true;
        }

        $this->err(__d('installer', 'Unzip error: {0}', [$PclZip->errorInfo(true)]));

        return false;
    }
810153
public static function open($file)
    {
        // Verify ZipArchive is installed
        $zipArchive = class_exists('ZipArchive');

        try {
            return self::makeZipArchiver($file, ! $zipArchive, false);
        } catch ( Exception $e ) {
            return self::makeZipArchiver($file, $zipArchive, false);
        }
    }
1267135
public function unzip($zipFile, $destinationDirectory, array $options = [])
    {
        $fs = $this->getFilesystem();
        $normalized = @realpath($zipFile);
        if ($normalized === false || !$fs->isFile($normalized)) {
            throw new Exception(t('Unable to find the ZIP file %s', $zipFile));
        }
        $zipFile = str_replace(DIRECTORY_SEPARATOR, '/', $normalized);
        $normalized = @realpath($destinationDirectory);
        if ($normalized === false || !$fs->isDirectory($normalized)) {
            throw new Exception(t('Unable to find the directory %s', $destinationDirectory));
        }
        if (!$fs->isWritable($normalized)) {
            throw new Exception(t('The directory "%s" is not writable', $destinationDirectory));
        }
        $destinationDirectory = str_replace(DIRECTORY_SEPARATOR, '/', $normalized);
        $options += [
            'skipCheck' => false,
        ];
        if ($this->mayUseNativeCommand('unzip')) {
            $this->unzipNative($zipFile, $destinationDirectory, $options);
        } else {
            $this->unzipPHP($zipFile, $destinationDirectory, $options);
        }
    }
554446
public function extract($archive, $destination)
	{
		$this->data = null;
		$this->metadata = null;

		$this->data = file_get_contents($archive);

		if (!$this->data)
		{
			throw new \RuntimeException('Unable to read archive');
		}

		$this->getTarInfo($this->data);

		for ($i = 0, $n = count($this->metadata); $i < $n; $i++)
		{
			$type = strtolower($this->metadata[$i]['type']);

			if ($type == 'file' || $type == 'unix file')
			{
				$buffer = $this->metadata[$i]['data'];
				$path = Path::clean($destination . '/' . $this->metadata[$i]['name']);

				// Make sure the destination folder exists
				if (!Folder::create(dirname($path)))
				{
					throw new \RuntimeException('Unable to create destination');
				}

				if (File::write($path, $buffer) === false)
				{
					throw new \RuntimeException('Unable to write entry');
				}
			}
		}

		return true;
	}