]> granicus.if.org Git - php/commitdiff
* better gzip detection (magic cookie)
authorStig Bakken <ssb@php.net>
Mon, 27 May 2002 19:28:09 +0000 (19:28 +0000)
committerStig Bakken <ssb@php.net>
Mon, 27 May 2002 19:28:09 +0000 (19:28 +0000)
pear/Archive/Tar.php

index 86bf0ee07a1efc41ab46d2c497bb646e6913566f..3796ae2451fa916b5097b972ba141d2a5633a646 100644 (file)
@@ -65,8 +65,20 @@ class Archive_Tar extends PEAR
     {
         $this->PEAR();
         if ($p_compress === null) {
-            if (substr($p_tarname, -4) == '.tar') {
-                $p_compress = false;
+            if (@file_exists($p_tarname)) {
+                if ($fp = @fopen($p_tarname, "r")) {
+                    // look for gzip magic cookie
+                    $data = fread($fp, 2);
+                    if ($data == "\37\213") {
+                        $p_compress = true;
+                    }
+                }
+            } else {
+                // probably a remote file or some file accessible
+                // through a stream interface
+                if (substr($p_tarname, -2) == 'gz') {
+                    $p_compress = true;
+                }
             }
         }
         $this->_tarname = $p_tarname;
@@ -86,7 +98,7 @@ class Archive_Tar extends PEAR
                 return false;
             }
         }
-        $this->_compress = $p_compress;
+        $this->_compress = (bool)$p_compress;
     }
     // }}}