From a33481a646b02e1fa4a2f2c3315bb3d1fbe695f6 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 12 Jul 2017 14:40:40 +0200 Subject: [PATCH] Create draft --- Utils/IO/Zip/Gz.php | 87 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/Utils/IO/Zip/Gz.php b/Utils/IO/Zip/Gz.php index 8b1378917..cf23e9939 100644 --- a/Utils/IO/Zip/Gz.php +++ b/Utils/IO/Zip/Gz.php @@ -1 +1,86 @@ - + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace phpOMS\Utils\IO\Zip; +/** + * Zip class for handling zip files. + * + * Providing basic zip support + * + * @category Framework + * @package phpOMS\Asset + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Gz implements ArchiveInterface +{ + /** + * Create zip. + * + * @param string $sources Files and directories to compress + * @param string $destination Output destination + * @param bool $overwrite Overwrite if destination is existing + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function pack(string $source, string $destination, bool $overwrite = true) : bool + { + $destination = str_replace('\\', '/', realpath($destination)); + if (!$overwrite && file_exists($destination)) { + return false; + } + + if(($gz = gzopen($destination, 'w')) === false) { + return false; + } + + $src = fopen($source, 'r'); + while(!feof($src)) { + gzwrite($gz, fgets($src)); + } + + fclose($src); + + return gzclose($gz); + } + + public static function unpack(string $source, string $destination) : bool + { + $destination = str_replace('\\', '/', realpath($destination)); + if (!$overwrite && file_exists($destination)) { + return false; + } + + if(($gz = gzopen($source, 'w')) === false) { + return false; + } + + $dest = fopen($destination, 'w'); + while (!gzeof($handle)) { + fwrite($dest, gzgets($handle, 4096)); + } + + fclose($dest); + + return gzclose($gz); + } +}