cvs: pear /File_Archive/Archive/Reader Bzip2.php Gzip.php Uncompress.php /File_Archive/Archive/Writer Tar.php /File_Archive/tests test.php
| From: | Vincent Lascaux | Date: | Sat, 16 Apr 2005 19:01:26 +0000 |
| Subject: | cvs: pear /File_Archive/Archive/Reader Bzip2.php Gzip.php Uncompress.php /File_Archive/Archive/Writer Tar.php /File_Archive/tests test.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-31197@lists.php.net to get a copy of this message | ||
vincentlascaux Sat Apr 16 15:01:26 2005 EDT
Modified files:
/pear/File_Archive/Archive/Reader Bzip2.php Gzip.php Uncompress.php
/pear/File_Archive/Archive/Writer Tar.php
/pear/File_Archive/tests test.php
Log:
Remove some debugging echo
Correct a GZip and BZ2 reader use less memory (use bz* and gz* functions on temporary files)
Correct bugs about readers not closed properly by uncompress reader
http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Bzip2.php?r1=1.2&r2=1.3&ty=u Index: pear/File_Archive/Archive/Reader/Bzip2.php diff -u pear/File_Archive/Archive/Reader/Bzip2.php:1.2 pear/File_Archive/Archive/Reader/Bzip2.php:1.3 --- pear/File_Archive/Archive/Reader/Bzip2.php:1.2 Sat Feb 26 05:34:23 2005 +++ pear/File_Archive/Archive/Reader/Bzip2.php Sat Apr 16 15:01:25 2005 @@ -25,28 +25,32 @@ * @author Vincent Lascaux <vincentlascaux@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.gnu.org/copyleft/lesser.html LGPL - * @version CVS: $Id: Bzip2.php,v 1.2 2005/02/26 10:34:23 vincentlascaux Exp $ + * @version CVS: $Id: Bzip2.php,v 1.3 2005/04/16 19:01:25 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ require_once "Archive.php"; +require_once "File/Archive/Writer/Files.php"; /** * Uncompress a file that was compressed in the Bzip2 format */ class File_Archive_Reader_Bzip2 extends File_Archive_Reader_Archive { - var $data = null; - var $offset = 0; var $alreadyRead = false; + var $bzfile = null; + var $tmpName = null; /** * @see File_Archive_Reader::close() */ function close() { - $this->data = null; - $this->offset = 0; + if($this->bzfile != null) + bzclose($this->bzfile); + if($this->tmpName != null) + unlink($this->tmpName); + $this->alreadyRead = false; return parent::close(); } @@ -65,13 +69,22 @@ } $this->alreadyRead = true; - $this->data = $this->source->getData(); - if (PEAR::isError($this->data)) { - return $this->data; - } + $dataFilename = $this->source->getDataFilename(); + if ($dataFilename != null) + { + $this->tmpName = null; + $this->bzfile = bzopen($dataFilename, 'r'); + } else { + $this->tmpName = tempnam('.', 'far'); + + //Generate the tmp data + $dest = new File_Archive_Writer_Files(); + $dest->newFile($this->tmpName); + $this->source->sendData($dest); + $dest->close(); - $this->data = bzdecompress($this->data); - $this->offset = 0; + $this->bzfile = bzopen($this->tmpName, 'r'); + } return true; } @@ -92,40 +105,24 @@ } } /** - * @see File_Archive_Reader::getStat() - */ - function getStat() - { - return array( - 7 => strlen($this->data) - ); - } - /** * @see File_Archive_Reader::getData() */ function getData($length = -1) { if ($length == -1) { - $actualLength = strlen($this->data) - $this->offset; + $data = ''; + do + { + $newData = bzread($this->bzfile); + $data .= $newData; + } while($newData != ''); + } else if ($length == 0) { + return ''; } else { - $actualLength = min(strlen($this->data) - $this->offset, $length); + $data = bzread($this->bzfile, $length); } - if ($actualLength == 0) { - return null; - } else { - $result = substr($this->data, $this->offset, $actualLength); - $this->offset += $actualLength; - return $result; - } - } - /** - * @see File_Archive_Reader::skip() - */ - function skip($length) - { - $this->offset += $length; - return $length; + return $data == '' ? null : $data; } } http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Gzip.php?r1=1.11&r2=1.12&ty=u Index: pear/File_Archive/Archive/Reader/Gzip.php diff -u pear/File_Archive/Archive/Reader/Gzip.php:1.11 pear/File_Archive/Archive/Reader/Gzip.php:1.12 --- pear/File_Archive/Archive/Reader/Gzip.php:1.11 Fri Apr 15 17:52:01 2005 +++ pear/File_Archive/Archive/Reader/Gzip.php Sat Apr 16 15:01:25 2005 @@ -25,32 +25,32 @@ * @author Vincent Lascaux <vincentlascaux@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.gnu.org/copyleft/lesser.html LGPL - * @version CVS: $Id: Gzip.php,v 1.11 2005/04/15 21:52:01 vincentlascaux Exp $ + * @version CVS: $Id: Gzip.php,v 1.12 2005/04/16 19:01:25 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ require_once "Archive.php"; +require_once "File/Archive/Writer/Files.php"; /** * Uncompress a file that was compressed in the Gzip format */ class File_Archive_Reader_Gzip extends File_Archive_Reader_Archive { - var $data = null; - var $offset = 0; var $alreadyRead = false; - - var $comment = null; - var $hasName = false; - var $hasComment = false; + var $gzfile = null; + var $tmpName = null; /** * @see File_Archive_Reader::close() */ function close() { - $this->data = null; - $this->offset = 0; + if($this->gzfile != null) + gzclose($this->gzfile); + if($this->tmpName != null) + unlink($this->tmpName); + $this->alreadyRead = false; return parent::close(); } @@ -69,59 +69,25 @@ } $this->alreadyRead = true; - $header = $this->source->getData(10); - if (PEAR::isError($header)) { - return $header; - } - - $id = unpack("H2id1/H2id2/C1tmp/C1flags",substr($header,0,4)); - if ($id['id1'] != "1f" || $id['id2'] != "8b") { - return PEAR::raiseError("Not valid gz file (wrong header)"); - } - - $temp = decbin($id['flags']); - $this->hasComment = ($temp & 0x4); + $dataFilename = $this->source->getDataFilename(); + if ($dataFilename != null) + { + $this->tmpName = null; + $this->gzfile = gzopen($dataFilename, 'r'); + } else { + $this->tmpName = tempnam('.', 'far'); - $this->comment = ""; - if ($this->hasComment) { - while (($char = $this->source->getData(1)) !== "\0") { - if ($char === null) { - return PEAR::raiseError( - "Not valid gz file (unexpected end of archive ". - "reading comment)" - ); - } - if (PEAR::isError($char)) { - return $char; - } - $this->comment .= $char; - } - } + //Generate the tmp data + $dest = new File_Archive_Writer_Files(); + $dest->newFile($this->tmpName); + $this->source->sendData($dest); + $dest->close(); - $this->data = $this->source->getData(); - if (PEAR::isError($this->data)) { - return $this->data; + $this->gzfile = gzopen($this->tmpName, 'r'); } - $temp = unpack("Vcrc32/Visize",substr($this->data,-8)); - $crc32 = $temp['crc32']; - $size = $temp['isize']; - - $this->data = gzinflate(substr($this->data,0,strlen($this->data)-8)); - $this->offset = 0; - - if ($size != strlen($this->data)) { - return PEAR::raiseError( - "Not valid gz file (size error {$size} != ". - strlen($this->data).")" - ); - } - if ($crc32 != crc32($this->data)) { - return PEAR::raiseError("Not valid gz file (checksum error)"); - } return true; } - /** * Return the name of the single file contained in the archive * deduced from the name of the archive (the extension is removed) @@ -138,42 +104,25 @@ return substr($name, 0, $pos); } } - - /** - * @see File_Archive_Reader::getStat() - */ - function getStat() - { - return array( - 7 => strlen($this->data) - ); - } /** * @see File_Archive_Reader::getData() */ function getData($length = -1) { if ($length == -1) { - $actualLength = strlen($this->data) - $this->offset; + $data = ''; + do + { + $newData = gzread($this->gzfile, 8196); + $data .= $newData; + } while($newData != ''); + } else if ($length == 0) { + return ''; } else { - $actualLength = min(strlen($this->data) - $this->offset, $length); + $data = gzread($this->gzfile, $length); } - if ($actualLength == 0) { - return null; - } else { - $result = substr($this->data, $this->offset, $actualLength); - $this->offset += $actualLength; - return $result; - } - } - /** - * @see File_Archive_Reader::skip() - */ - function skip($length) - { - $this->offset += $length; - return $length; + return $data == '' ? null : $data; } } http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Uncompress.php?r1=1.17&r2=1.18&ty=u Index: pear/File_Archive/Archive/Reader/Uncompress.php diff -u pear/File_Archive/Archive/Reader/Uncompress.php:1.17 pear/File_Archive/Archive/Reader/Uncompress.php:1.18 --- pear/File_Archive/Archive/Reader/Uncompress.php:1.17 Fri Apr 8 06:18:06 2005 +++ pear/File_Archive/Archive/Reader/Uncompress.php Sat Apr 16 15:01:25 2005 @@ -25,7 +25,7 @@ * @author Vincent Lascaux <vincentlascaux@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.gnu.org/copyleft/lesser.html LGPL - * @version CVS: $Id: Uncompress.php,v 1.17 2005/04/08 10:18:06 vincentlascaux Exp $ + * @version CVS: $Id: Uncompress.php,v 1.18 2005/04/16 19:01:25 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -189,6 +189,7 @@ //Remove the readers we have completly read from the stack do { while (($error = $this->source->next()) === false) { + $this->source->close(); if (empty($this->readers)) { return false; } @@ -279,6 +280,11 @@ */ function close() { + for($i=0; $i<count($this->readers); ++$i) { + $this->readers[$i]->close(); + } + + $this->readers = array(); $error = parent::close(); $this->source =& $this->startReader; http://cvs.php.net/diff.php/pear/File_Archive/Archive/Writer/Tar.php?r1=1.10&r2=1.11&ty=u Index: pear/File_Archive/Archive/Writer/Tar.php diff -u pear/File_Archive/Archive/Writer/Tar.php:1.10 pear/File_Archive/Archive/Writer/Tar.php:1.11 --- pear/File_Archive/Archive/Writer/Tar.php:1.10 Sat Apr 16 04:59:18 2005 +++ pear/File_Archive/Archive/Writer/Tar.php Sat Apr 16 15:01:25 2005 @@ -25,7 +25,7 @@ * @author Vincent Lascaux <vincentlascaux@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.gnu.org/copyleft/lesser.html LGPL - * @version CVS: $Id: Tar.php,v 1.10 2005/04/16 08:59:18 vincentlascaux Exp $ + * @version CVS: $Id: Tar.php,v 1.11 2005/04/16 19:01:25 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -53,7 +53,6 @@ */ function tarHeader($filename, $stat) { - echo "header ($filename)\n"; $mode = isset($stat[2]) ? $stat[2] : 0x8000; $uid = isset($stat[4]) ? $stat[4] : 0; $gid = isset($stat[5]) ? $stat[5] : 0; @@ -126,7 +125,6 @@ */ function tarFooter($size) { - echo "footer\n"; if ($size % 512 > 0) { return pack("a".(512 - $size%512), ""); } else { http://cvs.php.net/diff.php/pear/File_Archive/tests/test.php?r1=1.23&r2=1.24&ty=u Index: pear/File_Archive/tests/test.php diff -u pear/File_Archive/tests/test.php:1.23 pear/File_Archive/tests/test.php:1.24 --- pear/File_Archive/tests/test.php:1.23 Sat Apr 16 04:59:18 2005 +++ pear/File_Archive/tests/test.php Sat Apr 16 15:01:26 2005 @@ -247,7 +247,9 @@ require_once "File/Archive/Reader/Uncompress.php"; - $source = File_Archive::readSource($compressed->makeReader(), "$filename/$generated"); + $compressedReader = $compressed->makeReader(); + $source = File_Archive::readSource($compressedReader, "$filename/$generated"); + if(PEAR::isError($source)) echo ($extension); $source->extract(File_Archive::toVariable($uncompressed));
http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Bzip2.php?r1=1.2&r2=1.3&ty=u Index: pear/File_Archive/Archive/Reader/Bzip2.php diff -u pear/File_Archive/Archive/Reader/Bzip2.php:1.2 pear/File_Archive/Archive/Reader/Bzip2.php:1.3 --- pear/File_Archive/Archive/Reader/Bzip2.php:1.2 Sat Feb 26 05:34:23 2005 +++ pear/File_Archive/Archive/Reader/Bzip2.php Sat Apr 16 15:01:25 2005 @@ -25,28 +25,32 @@ * @author Vincent Lascaux <vincentlascaux@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.gnu.org/copyleft/lesser.html LGPL - * @version CVS: $Id: Bzip2.php,v 1.2 2005/02/26 10:34:23 vincentlascaux Exp $ + * @version CVS: $Id: Bzip2.php,v 1.3 2005/04/16 19:01:25 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ require_once "Archive.php"; +require_once "File/Archive/Writer/Files.php"; /** * Uncompress a file that was compressed in the Bzip2 format */ class File_Archive_Reader_Bzip2 extends File_Archive_Reader_Archive { - var $data = null; - var $offset = 0; var $alreadyRead = false; + var $bzfile = null; + var $tmpName = null; /** * @see File_Archive_Reader::close() */ function close() { - $this->data = null; - $this->offset = 0; + if($this->bzfile != null) + bzclose($this->bzfile); + if($this->tmpName != null) + unlink($this->tmpName); + $this->alreadyRead = false; return parent::close(); } @@ -65,13 +69,22 @@ } $this->alreadyRead = true; - $this->data = $this->source->getData(); - if (PEAR::isError($this->data)) { - return $this->data; - } + $dataFilename = $this->source->getDataFilename(); + if ($dataFilename != null) + { + $this->tmpName = null; + $this->bzfile = bzopen($dataFilename, 'r'); + } else { + $this->tmpName = tempnam('.', 'far'); + + //Generate the tmp data + $dest = new File_Archive_Writer_Files(); + $dest->newFile($this->tmpName); + $this->source->sendData($dest); + $dest->close(); - $this->data = bzdecompress($this->data); - $this->offset = 0; + $this->bzfile = bzopen($this->tmpName, 'r'); + } return true; } @@ -92,40 +105,24 @@ } } /** - * @see File_Archive_Reader::getStat() - */ - function getStat() - { - return array( - 7 => strlen($this->data) - ); - } - /** * @see File_Archive_Reader::getData() */ function getData($length = -1) { if ($length == -1) { - $actualLength = strlen($this->data) - $this->offset; + $data = ''; + do + { + $newData = bzread($this->bzfile); + $data .= $newData; + } while($newData != ''); + } else if ($length == 0) { + return ''; } else { - $actualLength = min(strlen($this->data) - $this->offset, $length); + $data = bzread($this->bzfile, $length); } - if ($actualLength == 0) { - return null; - } else { - $result = substr($this->data, $this->offset, $actualLength); - $this->offset += $actualLength; - return $result; - } - } - /** - * @see File_Archive_Reader::skip() - */ - function skip($length) - { - $this->offset += $length; - return $length; + return $data == '' ? null : $data; } } http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Gzip.php?r1=1.11&r2=1.12&ty=u Index: pear/File_Archive/Archive/Reader/Gzip.php diff -u pear/File_Archive/Archive/Reader/Gzip.php:1.11 pear/File_Archive/Archive/Reader/Gzip.php:1.12 --- pear/File_Archive/Archive/Reader/Gzip.php:1.11 Fri Apr 15 17:52:01 2005 +++ pear/File_Archive/Archive/Reader/Gzip.php Sat Apr 16 15:01:25 2005 @@ -25,32 +25,32 @@ * @author Vincent Lascaux <vincentlascaux@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.gnu.org/copyleft/lesser.html LGPL - * @version CVS: $Id: Gzip.php,v 1.11 2005/04/15 21:52:01 vincentlascaux Exp $ + * @version CVS: $Id: Gzip.php,v 1.12 2005/04/16 19:01:25 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ require_once "Archive.php"; +require_once "File/Archive/Writer/Files.php"; /** * Uncompress a file that was compressed in the Gzip format */ class File_Archive_Reader_Gzip extends File_Archive_Reader_Archive { - var $data = null; - var $offset = 0; var $alreadyRead = false; - - var $comment = null; - var $hasName = false; - var $hasComment = false; + var $gzfile = null; + var $tmpName = null; /** * @see File_Archive_Reader::close() */ function close() { - $this->data = null; - $this->offset = 0; + if($this->gzfile != null) + gzclose($this->gzfile); + if($this->tmpName != null) + unlink($this->tmpName); + $this->alreadyRead = false; return parent::close(); } @@ -69,59 +69,25 @@ } $this->alreadyRead = true; - $header = $this->source->getData(10); - if (PEAR::isError($header)) { - return $header; - } - - $id = unpack("H2id1/H2id2/C1tmp/C1flags",substr($header,0,4)); - if ($id['id1'] != "1f" || $id['id2'] != "8b") { - return PEAR::raiseError("Not valid gz file (wrong header)"); - } - - $temp = decbin($id['flags']); - $this->hasComment = ($temp & 0x4); + $dataFilename = $this->source->getDataFilename(); + if ($dataFilename != null) + { + $this->tmpName = null; + $this->gzfile = gzopen($dataFilename, 'r'); + } else { + $this->tmpName = tempnam('.', 'far'); - $this->comment = ""; - if ($this->hasComment) { - while (($char = $this->source->getData(1)) !== "\0") { - if ($char === null) { - return PEAR::raiseError( - "Not valid gz file (unexpected end of archive ". - "reading comment)" - ); - } - if (PEAR::isError($char)) { - return $char; - } - $this->comment .= $char; - } - } + //Generate the tmp data + $dest = new File_Archive_Writer_Files(); + $dest->newFile($this->tmpName); + $this->source->sendData($dest); + $dest->close(); - $this->data = $this->source->getData(); - if (PEAR::isError($this->data)) { - return $this->data; + $this->gzfile = gzopen($this->tmpName, 'r'); } - $temp = unpack("Vcrc32/Visize",substr($this->data,-8)); - $crc32 = $temp['crc32']; - $size = $temp['isize']; - - $this->data = gzinflate(substr($this->data,0,strlen($this->data)-8)); - $this->offset = 0; - - if ($size != strlen($this->data)) { - return PEAR::raiseError( - "Not valid gz file (size error {$size} != ". - strlen($this->data).")" - ); - } - if ($crc32 != crc32($this->data)) { - return PEAR::raiseError("Not valid gz file (checksum error)"); - } return true; } - /** * Return the name of the single file contained in the archive * deduced from the name of the archive (the extension is removed) @@ -138,42 +104,25 @@ return substr($name, 0, $pos); } } - - /** - * @see File_Archive_Reader::getStat() - */ - function getStat() - { - return array( - 7 => strlen($this->data) - ); - } /** * @see File_Archive_Reader::getData() */ function getData($length = -1) { if ($length == -1) { - $actualLength = strlen($this->data) - $this->offset; + $data = ''; + do + { + $newData = gzread($this->gzfile, 8196); + $data .= $newData; + } while($newData != ''); + } else if ($length == 0) { + return ''; } else { - $actualLength = min(strlen($this->data) - $this->offset, $length); + $data = gzread($this->gzfile, $length); } - if ($actualLength == 0) { - return null; - } else { - $result = substr($this->data, $this->offset, $actualLength); - $this->offset += $actualLength; - return $result; - } - } - /** - * @see File_Archive_Reader::skip() - */ - function skip($length) - { - $this->offset += $length; - return $length; + return $data == '' ? null : $data; } } http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Uncompress.php?r1=1.17&r2=1.18&ty=u Index: pear/File_Archive/Archive/Reader/Uncompress.php diff -u pear/File_Archive/Archive/Reader/Uncompress.php:1.17 pear/File_Archive/Archive/Reader/Uncompress.php:1.18 --- pear/File_Archive/Archive/Reader/Uncompress.php:1.17 Fri Apr 8 06:18:06 2005 +++ pear/File_Archive/Archive/Reader/Uncompress.php Sat Apr 16 15:01:25 2005 @@ -25,7 +25,7 @@ * @author Vincent Lascaux <vincentlascaux@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.gnu.org/copyleft/lesser.html LGPL - * @version CVS: $Id: Uncompress.php,v 1.17 2005/04/08 10:18:06 vincentlascaux Exp $ + * @version CVS: $Id: Uncompress.php,v 1.18 2005/04/16 19:01:25 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -189,6 +189,7 @@ //Remove the readers we have completly read from the stack do { while (($error = $this->source->next()) === false) { + $this->source->close(); if (empty($this->readers)) { return false; } @@ -279,6 +280,11 @@ */ function close() { + for($i=0; $i<count($this->readers); ++$i) { + $this->readers[$i]->close(); + } + + $this->readers = array(); $error = parent::close(); $this->source =& $this->startReader; http://cvs.php.net/diff.php/pear/File_Archive/Archive/Writer/Tar.php?r1=1.10&r2=1.11&ty=u Index: pear/File_Archive/Archive/Writer/Tar.php diff -u pear/File_Archive/Archive/Writer/Tar.php:1.10 pear/File_Archive/Archive/Writer/Tar.php:1.11 --- pear/File_Archive/Archive/Writer/Tar.php:1.10 Sat Apr 16 04:59:18 2005 +++ pear/File_Archive/Archive/Writer/Tar.php Sat Apr 16 15:01:25 2005 @@ -25,7 +25,7 @@ * @author Vincent Lascaux <vincentlascaux@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.gnu.org/copyleft/lesser.html LGPL - * @version CVS: $Id: Tar.php,v 1.10 2005/04/16 08:59:18 vincentlascaux Exp $ + * @version CVS: $Id: Tar.php,v 1.11 2005/04/16 19:01:25 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -53,7 +53,6 @@ */ function tarHeader($filename, $stat) { - echo "header ($filename)\n"; $mode = isset($stat[2]) ? $stat[2] : 0x8000; $uid = isset($stat[4]) ? $stat[4] : 0; $gid = isset($stat[5]) ? $stat[5] : 0; @@ -126,7 +125,6 @@ */ function tarFooter($size) { - echo "footer\n"; if ($size % 512 > 0) { return pack("a".(512 - $size%512), ""); } else { http://cvs.php.net/diff.php/pear/File_Archive/tests/test.php?r1=1.23&r2=1.24&ty=u Index: pear/File_Archive/tests/test.php diff -u pear/File_Archive/tests/test.php:1.23 pear/File_Archive/tests/test.php:1.24 --- pear/File_Archive/tests/test.php:1.23 Sat Apr 16 04:59:18 2005 +++ pear/File_Archive/tests/test.php Sat Apr 16 15:01:26 2005 @@ -247,7 +247,9 @@ require_once "File/Archive/Reader/Uncompress.php"; - $source = File_Archive::readSource($compressed->makeReader(), "$filename/$generated"); + $compressedReader = $compressed->makeReader(); + $source = File_Archive::readSource($compressedReader, "$filename/$generated"); + if(PEAR::isError($source)) echo ($extension); $source->extract(File_Archive::toVariable($uncompressed));