Beispiel #1
0
 /**
  * Uncompresses a known archive identified by $file.
  * Returns the path to the folder it created.
  * If $show_errors is true, it outputs errors in html.
  */
 public static function uncompress($file, $show_errors)
 {
     // Tar (.tar) archives, including those compressed with gzip (.tar.gz, .tgz), bzip (.tar.bz, .tbz), bzip2 (.tar.bz2, .tbz2), compress (.tar.Z, .taz), lzop (.tar.lzo, .tzo) and lzma (.tar.lzma)
     // Zip archives (.zip)
     // Jar archives (.jar, .ear, .war)
     // 7z archives (.7z)
     // iso9660 CD images (.iso)
     // Lha archives (.lzh)
     // Single files compressed with gzip (.gz), bzip (.bz), bzip2 (.bz2), compress (.Z), lzop (.lzo) and lzma (.lzma)
     $suffix = pathinfo($file, PATHINFO_EXTENSION);
     switch ($suffix) {
         case "tar.gz":
             // Never called because pathinfo would give the 'gz' suffix only.
         // Never called because pathinfo would give the 'gz' suffix only.
         case "gz":
         case "tgz":
             return Filter_Archive::untargz($file, $show_errors);
         case "zip":
             return Filter_Archive::unzip($file, $show_errors);
         case "tar.bz":
         case "tbz":
         case "tar.bz2":
         case "tbz2":
     }
     return NULL;
 }
Beispiel #2
0
 public function testFilterArchiveUntargz()
 {
     $tarball = Filter_Archive::tarGzipFile($this->file1, false);
     // Test decompression.
     $folder = Filter_Archive::untargz($tarball, false);
     $this->assertTrue(file_exists($folder));
     Filter_Rmdir::rmdir($folder);
     $folder = Filter_Archive::uncompress($tarball, false);
     $this->assertTrue(file_exists($folder));
     foreach (new DirectoryIterator($folder) as $fileInfo) {
         if ($fileInfo->isDot()) {
             continue;
         }
         $path = $fileInfo->getFilename();
         $path = "{$folder}/{$path}";
         $this->assertEquals(9000, filesize($path));
     }
     Filter_Rmdir::rmdir($folder);
     unlink($tarball);
     // Test that unzipping garbage returns NULL.
     $folder = Filter_Archive::untargz("xxxxx", false);
     $this->assertEquals(NULL, $folder);
 }