Exemplo n.º 1
0
 public function testRecognizeTarGnu()
 {
     $dir = $this->getTempDir();
     copy(dirname(__FILE__) . "/data/tar_gnu_2_textfiles.tar", "{$dir}/my.tar");
     $this->assertEquals(ezcArchive::TAR_GNU, ezcArchiveFileType::detect("{$dir}/my.tar"));
 }
Exemplo n.º 2
0
 /**
  * Returns a new ezcArchive instance.
  *
  * This method returns a new instance according to the mime-type or
  * the given $forceType.
  *
  * - If $forceType is set to null, this method will try to determine the
  *   archive format via the file data. Therefore the $forceType can only be
  *   null when the archive contains data.
  * - If $forceType is set, it will use the specified algorithm. Even when
  *   the given archive is from another type than specified.
  *
  * @throws ezcArchiveUnknownTypeException if the type of the archive cannot be determined.
  *
  * @param string  $archiveName  Absolute or relative path to the archive.
  * @param int     $forceType    Open the archive with the $forceType
  *        algorithm. Possible values are: {@link ezcArchive::ZIP},
  *        {@link ezcArchive::TAR}, {@link ezcArchive::TAR_V7}, {@link ezcArchive::TAR_USTAR},
  *        {@link ezcArchive::TAR_PAX}, {@link ezcArchive::TAR_GNU}.
  *        TAR will use the TAR_USTAR algorithm by default.
  * @param ezcArchiveOptions $options
  *
  * @return ezcArchive
  */
 public static function open($archiveName, $forceType = null, ezcArchiveOptions $options = null)
 {
     $options = self::initOptions($options);
     if (!ezcArchiveFile::fileExists($archiveName) && $forceType === null) {
         throw new ezcArchiveUnknownTypeException($archiveName);
     }
     if ($forceType !== null) {
         return self::createInstance($archiveName, $forceType, $options);
     }
     $h = ezcArchiveFileType::detect($archiveName);
     while ($h == ezcArchive::GZIP || $h == ezcArchive::BZIP2) {
         if ($h == ezcArchive::GZIP) {
             $archiveName = "compress.zlib://{$archiveName}";
             $h = ezcArchiveFileType::detect($archiveName);
         }
         if ($h == ezcArchive::BZIP2) {
             $archiveName = "compress.bzip2://{$archiveName}";
             $h = ezcArchiveFileType::detect($archiveName);
         }
     }
     return self::createInstance($archiveName, $h, $options);
 }