19 declare(strict_types=1);
46 $this->zip_options = $this->archives->zipOptions();
47 $this->unzip_options = $this->archives->unzipOptions();
54 string $directory_to_zip,
55 string $path_to_output_zip,
56 bool $ensure_top_directory =
false 58 $directory_to_zip = $this->normalizePath($directory_to_zip);
59 $path_to_output_zip = $this->normalizePath($path_to_output_zip);
61 $zip = $this->archives->zip(
64 ->withZipOutputPath(dirname($path_to_output_zip))
65 ->withZipOutputName(basename($path_to_output_zip))
66 ->withDirectoryHandling($ensure_top_directory ? ZipDirectoryHandling::ENSURE_SINGLE_TOP_DIR : ZipDirectoryHandling::KEEP_STRUCTURE)
69 $zip->addDirectory($directory_to_zip);
70 $zip_stream = $zip->get();
72 return $zip_stream->getSize() > 0;
80 string $extract_to_path = null,
81 bool $overwrite =
false,
83 bool $ensure_top_directory =
false 85 $extract_to_path ??= dirname($path_to_zip);
89 $dir_handling = $ensure_top_directory ? ZipDirectoryHandling::ENSURE_SINGLE_TOP_DIR : ZipDirectoryHandling::KEEP_STRUCTURE;
92 $unzip = $this->archives->unzip(
93 Streams::ofResource(fopen($path_to_zip,
'rb')),
95 ->withZipOutputPath($extract_to_path)
96 ->withOverwrite($overwrite)
97 ->withDirectoryHandling($dir_handling)
99 return $unzip->extract();
Will keep the top directory of the ZIP file if there is one (simple unzip).
zip(string $directory_to_zip, string $path_to_output_zip, bool $ensure_top_directory=false)
UnzipOptions $unzip_options
unzip(string $path_to_zip, string $extract_to_path=null, bool $overwrite=false, bool $flat=false, bool $ensure_top_directory=false)