compress() public static method

Static method to compress data
public static compress ( string $data, integer $level = 9, integer $mode = FORCE_GZIP ) : mixed
$data string
$level integer
$mode integer
return mixed
Beispiel #1
0
 public function testGzipWithFile()
 {
     if (function_exists('gzcompress')) {
         $compressed = Gzip::compress(__DIR__ . '/../tmp/access.txt');
         $this->fileExists(__DIR__ . '/../tmp/access.txt.gz');
         $decompressed = Gzip::decompress($compressed);
         $this->fileExists(__DIR__ . '/../tmp/access.txt');
         if (file_exists(__DIR__ . '/../tmp/access.txt.gz')) {
             unlink(__DIR__ . '/../tmp/access.txt.gz');
         }
     }
 }
Beispiel #2
0
 /**
  * Method to compress an archive file with Gzip or Bzip2
  *
  * @param  string $ext
  * @return \Pop\Archive\Archive
  */
 public function compress($ext = 'gz')
 {
     if ($ext == 'bz') {
         $ext .= '2';
     }
     switch ($ext) {
         case 'gz':
             $newArchive = Compress\Gzip::compress($this->fullpath);
             break;
         case 'tgz':
             $tmpArchive = Compress\Gzip::compress($this->fullpath);
             $newArchive = str_replace('.tar.gz', '.tgz', $tmpArchive);
             rename($tmpArchive, $newArchive);
             break;
         case 'bz2':
             $newArchive = Compress\Bzip2::compress($this->fullpath);
             break;
         case 'tbz':
             $tmpArchive = Compress\Bzip2::compress($this->fullpath);
             $newArchive = str_replace('.tar.bz2', '.tbz', $tmpArchive);
             rename($tmpArchive, $newArchive);
             break;
         case 'tbz2':
             $tmpArchive = Compress\Bzip2::compress($this->fullpath);
             $newArchive = str_replace('.tar.bz2', '.tbz2', $tmpArchive);
             rename($tmpArchive, $newArchive);
             break;
         default:
             $newArchive = $this->fullpath;
     }
     if (file_exists($this->fullpath)) {
         unlink($this->fullpath);
     }
     self::__construct($newArchive);
     return $this;
 }