| @@ 11-40 (lines=30) @@ | ||
| 8 | */ |
|
| 9 | namespace GpsLab\Component\Sitemap\Compressor; |
|
| 10 | ||
| 11 | class Bzip2Compressor implements CompressorInterface |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * @param string $source |
|
| 15 | * @param string $target |
|
| 16 | * |
|
| 17 | * @return bool |
|
| 18 | */ |
|
| 19 | public function compress($source, $target = '') |
|
| 20 | { |
|
| 21 | $target = $target ?: $source.'.bz2'; |
|
| 22 | $rh = @fopen($source, 'rb'); |
|
| 23 | $bz = @bzopen($target, 'w9'); |
|
| 24 | ||
| 25 | if ($rh === false || $bz === false) { |
|
| 26 | return false; |
|
| 27 | } |
|
| 28 | ||
| 29 | while (!feof($rh)) { |
|
| 30 | if (bzwrite($bz, fread($rh, 1024)) === false) { |
|
| 31 | return false; |
|
| 32 | } |
|
| 33 | } |
|
| 34 | ||
| 35 | fclose($rh); |
|
| 36 | bzclose($bz); |
|
| 37 | ||
| 38 | return true; |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| @@ 11-40 (lines=30) @@ | ||
| 8 | */ |
|
| 9 | namespace GpsLab\Component\Sitemap\Compressor; |
|
| 10 | ||
| 11 | class GzipCompressor implements CompressorInterface |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * @param string $source |
|
| 15 | * @param string $target |
|
| 16 | * |
|
| 17 | * @return bool |
|
| 18 | */ |
|
| 19 | public function compress($source, $target = '') |
|
| 20 | { |
|
| 21 | $target = $target ?: $source.'.gz'; |
|
| 22 | $rh = @fopen($source, 'rb'); |
|
| 23 | $gz = @gzopen($target, 'w9'); |
|
| 24 | ||
| 25 | if ($rh === false || $gz === false) { |
|
| 26 | return false; |
|
| 27 | } |
|
| 28 | ||
| 29 | while (!feof($rh)) { |
|
| 30 | if (gzwrite($gz, fread($rh, 1024)) === false) { |
|
| 31 | return false; |
|
| 32 | } |
|
| 33 | } |
|
| 34 | ||
| 35 | fclose($rh); |
|
| 36 | gzclose($gz); |
|
| 37 | ||
| 38 | return true; |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||