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'); } } }
/** * Method to extract an archived and/or compressed file * * @param string $to * @return void */ public function extract($to = null) { if ($this->compression == 'bz') { $this->path = Compress\Bzip2::decompress($this->path); $this->archive = new \Archive_Tar($this->path); } else { if ($this->compression == 'gz') { $this->path = Compress\Gzip::decompress($this->path); $this->archive = new \Archive_Tar($this->path); } } $this->archive->extract(null !== $to ? $to : './'); }
/** * 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; }