cvs: php4 /pear/Archive Tar.php

From: Date: Mon, 27 May 2002 19:28:09 +0000
Subject: cvs: php4 /pear/Archive Tar.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-4162@lists.php.net to get a copy of this message
ssb Mon May 27 15:28:09 2002 EDT Modified files: /php4/pear/Archive Tar.php Log: * better gzip detection (magic cookie) Index: php4/pear/Archive/Tar.php diff -u php4/pear/Archive/Tar.php:1.10 php4/pear/Archive/Tar.php:1.11 --- php4/pear/Archive/Tar.php:1.10 Mon May 27 07:59:09 2002 +++ php4/pear/Archive/Tar.php Mon May 27 15:28:09 2002 @@ -16,7 +16,7 @@ // | Author: Vincent Blavet <vincent@blavet.net> | // +----------------------------------------------------------------------+ // -// $Id: Tar.php,v 1.10 2002/05/27 11:59:09 ssb Exp $ +// $Id: Tar.php,v 1.11 2002/05/27 19:28:09 ssb Exp $ require_once 'PEAR.php'; @@ -24,7 +24,7 @@ * Creates a (compressed) Tar archive * * @author Vincent Blavet <vincent@blavet.net> -* @version $Revision: 1.10 $ +* @version $Revision: 1.11 $ * @package Archive */ class Archive_Tar extends PEAR @@ -65,8 +65,20 @@ { $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 @@ return false; } } - $this->_compress = $p_compress; + $this->_compress = (bool)$p_compress; } // }}}

« previous php.pear.cvs (#4162) next »