Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| TarGz | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
9 | |
100.00% |
1 / 1 |
| pack | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
5 | |||
| unpack | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Utils\IO\Zip |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Utils\IO\Zip; |
| 16 | |
| 17 | use phpOMS\System\File\Local\File; |
| 18 | |
| 19 | /** |
| 20 | * Zip class for handling zip files. |
| 21 | * |
| 22 | * Providing basic zip support |
| 23 | * |
| 24 | * @package phpOMS\Utils\IO\Zip |
| 25 | * @license OMS License 2.0 |
| 26 | * @link https://jingga.app |
| 27 | * @since 1.0.0 |
| 28 | */ |
| 29 | class TarGz implements ArchiveInterface |
| 30 | { |
| 31 | /** |
| 32 | * {@inheritdoc} |
| 33 | */ |
| 34 | public static function pack(string | array $source, string $destination, bool $overwrite = false) : bool |
| 35 | { |
| 36 | $destination = \strtr($destination, '\\', '/'); |
| 37 | if (!$overwrite && \is_file($destination)) { |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | if (!Tar::pack($source, $destination . '.tmp', $overwrite)) { |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | $pack = Gz::pack($destination . '.tmp', $destination, $overwrite); |
| 46 | |
| 47 | if ($pack) { |
| 48 | \unlink($destination . '.tmp'); |
| 49 | } |
| 50 | |
| 51 | return $pack; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * {@inheritdoc} |
| 56 | */ |
| 57 | public static function unpack(string $source, string $destination) : bool |
| 58 | { |
| 59 | $destination = \strtr($destination, '\\', '/'); |
| 60 | if (!\is_dir($destination) || !\is_file($source)) { |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | if (!Gz::unpack($source, $destination . '/' . File::name($source) . '.tmp')) { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | $unpacked = Tar::unpack($destination . '/' . File::name($source) . '.tmp', $destination); |
| 69 | \unlink($destination . '/' . File::name($source) . '.tmp'); |
| 70 | |
| 71 | return $unpacked; |
| 72 | } |
| 73 | } |