compress() public method

Method to compress an archive file with Gzip or Bzip2
public compress ( string $ext = 'gz' ) : Archive
$ext string
return Archive
Exemplo n.º 1
0
<?php

require_once '../../bootstrap.php';
use Pop\Archive\Archive;
try {
    // Create a new TAR archive and add some files to it
    // (Make sure the '../tmp' folder is writable)
    $archive = new Archive('../tmp/test.tar');
    $archive->addFiles('../assets');
    // Display the new archive file size
    echo $archive->getBasename() . ': file size => ' . $archive->getSize() . '<br /> ' . PHP_EOL;
    // Compress the archive (Gzip by default)
    $archive->compress('bz');
    // Display the newly compressed archive file size
    echo $archive->getBasename() . ': compressed file size => ' . $archive->getSize() . '<br /> ' . PHP_EOL;
    echo 'Done.';
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
Exemplo n.º 2
0
 public function testNoCompress()
 {
     $tar = false;
     $includePath = explode(PATH_SEPARATOR, get_include_path());
     foreach ($includePath as $path) {
         if (file_exists($path . DIRECTORY_SEPARATOR . 'Archive' . DIRECTORY_SEPARATOR . 'Tar.php')) {
             $tar = true;
         }
     }
     if ($tar) {
         $a = new Archive(__DIR__ . '/../tmp/test.tar');
         $a->addFiles(__DIR__ . '/../tmp');
         $a->compress('.noext');
         $this->fileExists(__DIR__ . '/../tmp/test.tar');
         if (file_exists(__DIR__ . '/../tmp/test.tar')) {
             unlink(__DIR__ . '/../tmp/test.tar');
         }
     }
 }