cvs: pear /File_Archive/Archive Reader.php /File_Archive/Archive/Reader Ar.php Bzip2.php Concat.php File.php Gzip.php Memory.php Relay.php Tar.php
Zip.php
| From: | Vincent Lascaux | Date: | Sat, 28 May 2005 00:58:49 +0000 |
| Subject: | cvs: pear /File_Archive/Archive Reader.php /File_Archive/Archive/Reader Ar.php Bzip2.php Concat.php File.php Gzip.php Memory.php Relay.php Tar.php Zip.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-32172@lists.php.net to get a copy of this message | ||
vincentlascaux Fri May 27 20:58:49 2005 EDT
Modified files:
/pear/File_Archive/Archive Reader.php
/pear/File_Archive/Archive/Reader Ar.php Bzip2.php Concat.php
File.php Gzip.php Memory.php
Relay.php Tar.php Zip.php
Log:
+ Create a new interface for the reader that will allow to add, remove, edit files in an archive
(which also means in a nested archive...)
+ Implements the rewind function for majority of the readers
http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader.php?r1=1.24&r2=1.25&ty=u Index: pear/File_Archive/Archive/Reader.php diff -u pear/File_Archive/Archive/Reader.php:1.24 pear/File_Archive/Archive/Reader.php:1.25 --- pear/File_Archive/Archive/Reader.php:1.24 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader.php Fri May 27 20:58:46 2005 @@ -27,7 +27,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: Reader.php,v 1.24 2005/05/26 21:30:18 vincentlascaux Exp $ + * @version CVS: $Id: Reader.php,v 1.25 2005/05/28 00:58:46 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -199,6 +199,21 @@ } /** + * Move the current position back of a given amount of bytes. + * Not all readers may implement this function (a PEAR error will + * be returned if the reader can't rewind) + * + * @param int $length number of bytes to seek before the current pos + * or -1 to move back to the begining of the current file + * @return the number of bytes really rewinded (which may be less than + * $length if the current pos is less than $length + */ + function rewind($length) + { + return PEAR::raiseError('Rewind function is not implemented on this reader'); + } + + /** * Put back the reader in the state it was before the first call * to next() * @@ -315,6 +330,57 @@ } /** + * Remove the current file from the archive + * After having removed a file from an archive, the current position in the + * archive is set to the next file in the archive + */ + function remove() + { + } + + /** + * Remove some data from the current file in the archive + * After having removed a block of data, the current position in the archive + * is will be after the removed block of data, in the current file that may have + * been moved + * + * @param int $seek Relative position of the begining of the block that must + * be removed, from the current pos + * @param int $size Size of the block (in bytes) to remove, or -1 to remove to + * the end of the file + */ + function removeBlock($seek = 0, $size = -1) + { + } + + /** + * Create a writer to append files to the archive + * After having called this function, $this will be closed and should no longer be used + * + * @return File_Archive_Writer writer on which you can call newFile to append new files + * in the archive + */ + function makeAppendWriter() + { + $this->skip(-1); + return $this->makeDataWriter(); + } + + /** + * Create a writer to append data to the current file, erasing it from current pos + * After having called this function, $this will be closed and should no longer be used + * The order of the files in the archive may not be preserved + * + * Note: if you won't modify the data of the file, use makeAppendWriter which is way faster + * + * @return File_Archive_Writer writer on which you can call writeData to append data to the + * current file in the archive, or newFile to append files + */ + function makeDataWriter($seek = 0) + { + } + + /** * Returns a writer that will start writing at the current pos in the source * Any data (from current file or any other file) located after current pos * will be erased. http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Ar.php?r1=1.7&r2=1.8&ty=u Index: pear/File_Archive/Archive/Reader/Ar.php diff -u pear/File_Archive/Archive/Reader/Ar.php:1.7 pear/File_Archive/Archive/Reader/Ar.php:1.8 --- pear/File_Archive/Archive/Reader/Ar.php:1.7 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader/Ar.php Fri May 27 20:58:48 2005 @@ -194,6 +194,45 @@ } /** + * @see File_Archive_Reader::skip + */ + function skip($length) + { + if ($length == -1) { + $length = $this->_nbBytesLeft; + } else { + $length = min($length, $this->_nbBytesLeft); + } + if ($length == 0) { + return 0; + } else { + $this->_nbBytesLeft -= $length; + return $this->source->skip($length); + } + } + + /** + * @see File_Archive_Reader::rewind + */ + function rewind($length) + { + if ($length == -1) { + $length = $this->_currentStat[7] - $this->_nbBytesLeft; + } else { + $length = min($length, $this->_currentStat[7] - $this->_nbBytesLeft); + } + if ($length == 0) { + return 0; + } else { + $rewinded = $this->source->rewind($length); + if (!PEAR::isError($rewinded)) { + $this->_nbBytesLeft += $rewinded; + } + return $rewinded; + } + } + + /** * @see File_Archive_Reader::makeWriter */ function makeWriter($seek = 0, $fileModif = true) http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Bzip2.php?r1=1.11&r2=1.12&ty=u Index: pear/File_Archive/Archive/Reader/Bzip2.php diff -u pear/File_Archive/Archive/Reader/Bzip2.php:1.11 pear/File_Archive/Archive/Reader/Bzip2.php:1.12 --- pear/File_Archive/Archive/Reader/Bzip2.php:1.11 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader/Bzip2.php Fri May 27 20:58:48 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: Bzip2.php,v 1.11 2005/05/26 21:30:18 vincentlascaux Exp $ + * @version CVS: $Id: Bzip2.php,v 1.12 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -134,6 +134,15 @@ } /** + * @see File_Archive_Reader::rewind + */ + function rewind($length) + { + //TODO: implement rewind + return parent::rewind($length); + } + + /** * @see File_Archive_Reader::makeWriter */ function makeWriter($fileModif = true, $seek = 0) http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Concat.php?r1=1.12&r2=1.13&ty=u Index: pear/File_Archive/Archive/Reader/Concat.php diff -u pear/File_Archive/Archive/Reader/Concat.php:1.12 pear/File_Archive/Archive/Reader/Concat.php:1.13 --- pear/File_Archive/Archive/Reader/Concat.php:1.12 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader/Concat.php Fri May 27 20:58:48 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: Concat.php,v 1.12 2005/05/26 21:30:18 vincentlascaux Exp $ + * @version CVS: $Id: Concat.php,v 1.13 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -146,6 +146,14 @@ return $skipped; } /** + * @see File_Archive_Reader::rewind() + */ + function rewind($length) + { + //TODO: implement rewind + return parent::rewind($length); + } + /** * @see File_Archive_Reader::close() */ function close() http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/File.php?r1=1.18&r2=1.19&ty=u Index: pear/File_Archive/Archive/Reader/File.php diff -u pear/File_Archive/Archive/Reader/File.php:1.18 pear/File_Archive/Archive/Reader/File.php:1.19 --- pear/File_Archive/Archive/Reader/File.php:1.18 Thu May 26 11:57:37 2005 +++ pear/File_Archive/Archive/Reader/File.php Fri May 27 20:58:48 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: File.php,v 1.18 2005/05/26 15:57:37 vincentlascaux Exp $ + * @version CVS: $Id: File.php,v 1.19 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -168,13 +168,15 @@ } } } + /** - * @see File_Archive_Reader::Skip() + * @see File_Archive_Reader::skip() */ function skip($length) { $before = ftell($this->handle); - if (@fseek($this->handle, $length, SEEK_CUR) === -1) { + if (($length == -1 && @fseek($this->handle, 0, SEEK_END) === -1) || + ($length >= 0 && @fseek($this->handle, $length, SEEK_CUR) === -1)) { return parent::skip($length); } else { return ftell($this->handle) - $before; @@ -182,6 +184,20 @@ } /** + * @see File_Archive_Reader::rewind + */ + function rewind($length) + { + $before = ftell($this->handle); + if (($length == -1 && @fseek($this->handle, 0, SEEK_SET) === -1) || + ($length >= 0 && @fseek($this->handle, -$length, SEEK_CUR) === -1)) { + return parent::rewind($length); + } else { + return $before - ftell($this->handle); + } + } + + /** * @see File_Archive_Reader::makeWriter */ function makeWriter($fileModif = true, $seek = 0) http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Gzip.php?r1=1.20&r2=1.21&ty=u Index: pear/File_Archive/Archive/Reader/Gzip.php diff -u pear/File_Archive/Archive/Reader/Gzip.php:1.20 pear/File_Archive/Archive/Reader/Gzip.php:1.21 --- pear/File_Archive/Archive/Reader/Gzip.php:1.20 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader/Gzip.php Fri May 27 20:58:48 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: Gzip.php,v 1.20 2005/05/26 21:30:18 vincentlascaux Exp $ + * @version CVS: $Id: Gzip.php,v 1.21 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -38,6 +38,7 @@ class File_Archive_Reader_Gzip extends File_Archive_Reader_Archive { var $nbRead = 0; + var $filePos = 0; var $gzfile = null; var $tmpName = null; @@ -54,6 +55,7 @@ } $this->nbRead = 0; + $this->filePos = 0; $this->gzfile = null; $this->tmpName = null; @@ -70,6 +72,7 @@ } $this->nbRead++; + $this->filePos = 0; if ($this->nbRead > 1) { return false; } @@ -93,6 +96,7 @@ return true; } + /** * Return the name of the single file contained in the archive * deduced from the name of the archive (the extension is removed) @@ -113,6 +117,7 @@ return $name; } + /** * @see File_Archive_Reader::getData() */ @@ -122,7 +127,7 @@ $data = ''; do { - $newData = gzread($this->gzfile, 8196); + $newData = gzread($this->gzfile, 8192); $data .= $newData; } while ($newData != ''); } else if ($length == 0) { @@ -131,10 +136,57 @@ $data = gzread($this->gzfile, $length); } + $this->filePos += strlen($data); return $data == '' ? null : $data; } /** + * @see File_Archive_Reader::skip() + */ + function skip($length) + { + if($length == -1) { + do + { + $tmp = gzread($this->gzfile, 8192); + $this->filePos += strlen($tmp); + } while ($tmp != ''); + } else { + if (@gzseek($this->gzfile, $this->filePos + $length) === -1) { + return parent::skip($length); + } else { + $this->filePos += $length; + return $length; + } + } + } + + /** + * @see File_Archive_Reader::rewind() + */ + function rewind($length) + { + if ($length == -1) { + if (@gzseek($this->gzfile, 0) === -1) { + return parent::rewind($length); + } else { + $tmp = $this->filePos; + $this->filePos = 0; + return $tmp; + } + } else { + $length = min($length, $this->filePos); + if (@gzseek($this->gzfile, $this->filePos - $length) === -1) { + return parent::rewind($length); + } else { + $this->filePos -= $length; + return $length; + } + } + } + + + /** * @see File_Archive_Reader::makeWriter */ function makeWriter($fileModif = true, $seek = 0) http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Memory.php?r1=1.14&r2=1.15&ty=u Index: pear/File_Archive/Archive/Reader/Memory.php diff -u pear/File_Archive/Archive/Reader/Memory.php:1.14 pear/File_Archive/Archive/Reader/Memory.php:1.15 --- pear/File_Archive/Archive/Reader/Memory.php:1.14 Thu May 26 12:12:19 2005 +++ pear/File_Archive/Archive/Reader/Memory.php Fri May 27 20:58:48 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: Memory.php,v 1.14 2005/05/26 16:12:19 vincentlascaux Exp $ + * @version CVS: $Id: Memory.php,v 1.15 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -133,15 +133,37 @@ $this->offset += $actualLength; return $result; } + /** * @see File_Archive_Reader::skip() */ function skip($length) { - $actualLength = min($length, strlen($this->memory) - $this->offset); - $this->offset += $actualLength; - return $actualLength; + if ($length == -1) { + $length = strlen($this->memory) - $this->offset; + } else { + $length = min($length, strlen($this->memory) - $this->offset); + } + $this->offset += $length; + return $length; + } + + /** + * @see File_Archive_Reader::rewind() + */ + function rewind($length) + { + if ($length == -1) { + $tmp = $this->offset; + $this->offset = 0; + return $tmp; + } else { + $length = min($length, $this->offset); + $this->offset -= $length; + return $length; + } } + /** * @see File_Archive_Reader::close() */ http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Relay.php?r1=1.12&r2=1.13&ty=u Index: pear/File_Archive/Archive/Reader/Relay.php diff -u pear/File_Archive/Archive/Reader/Relay.php:1.12 pear/File_Archive/Archive/Reader/Relay.php:1.13 --- pear/File_Archive/Archive/Reader/Relay.php:1.12 Thu May 26 11:57:37 2005 +++ pear/File_Archive/Archive/Reader/Relay.php Fri May 27 20:58:48 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: Relay.php,v 1.12 2005/05/26 15:57:37 vincentlascaux Exp $ + * @version CVS: $Id: Relay.php,v 1.13 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -79,6 +79,10 @@ */ function skip($length) { return $this->source->skip($length); } /** + * @see File_Archive_Reader::rewind() + */ + function rewind($length) { return $this->source->rewind($length); } + /** * @see File_Archive_Reader::close() */ function close() http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Tar.php?r1=1.20&r2=1.21&ty=u Index: pear/File_Archive/Archive/Reader/Tar.php diff -u pear/File_Archive/Archive/Reader/Tar.php:1.20 pear/File_Archive/Archive/Reader/Tar.php:1.21 --- pear/File_Archive/Archive/Reader/Tar.php:1.20 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader/Tar.php Fri May 27 20:58:48 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.20 2005/05/26 21:30:18 vincentlascaux Exp $ + * @version CVS: $Id: Tar.php,v 1.21 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -71,10 +71,33 @@ */ function skip($length) { - $actualLength = min($this->leftLength, $length); - $error = $this->source->skip($actualLength); - $this->leftLength -= $actualLength; - return $error; + if ($length == -1) { + $length = $this->leftLength; + } else { + $length = min($this->leftLength, $length); + } + $skipped = $this->source->skip($length); + if (!PEAR::isError($skipped)) { + $this->leftLength -= $skipped; + } + return $skipped; + } + + /** + * @see File_Archive_Reader::rewind() + */ + function rewind($length) + { + if ($length == -1) { + $length = $this->currentStat[7] - $this->leftLength; + } else { + $length = min($length, $this->currentStat[7] - $this->leftLength); + } + $rewinded = $this->source->rewind($length); + if (!PEAR::isError($rewinded)) { + $this->leftLength += $rewinded; + } + return $rewinded; } /** http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Zip.php?r1=1.18&r2=1.19&ty=u Index: pear/File_Archive/Archive/Reader/Zip.php diff -u pear/File_Archive/Archive/Reader/Zip.php:1.18 pear/File_Archive/Archive/Reader/Zip.php:1.19 --- pear/File_Archive/Archive/Reader/Zip.php:1.18 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader/Zip.php Fri May 27 20:58:49 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: Zip.php,v 1.18 2005/05/26 21:30:18 vincentlascaux Exp $ + * @version CVS: $Id: Zip.php,v 1.19 2005/05/28 00:58:49 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -215,8 +215,28 @@ */ function skip($length) { - $this->offset = min($this->offset + $length, $this->currentStat[7]); + $before = $this->offset; + if ($length == -1) { + $this->offset = $this->currentStat[7]; + } else { + $this->offset = min($this->offset + $length, $this->currentStat[7]); + } + return $this->offset - $before; } + /** + * @see File_Archive_Reader::rewind() + */ + function rewind($length) + { + $before = $this->offset; + if ($length == -1) { + $this->offset = 0; + } else { + $this->offset = min(0, $this->offset - $length); + } + return before - $this->offset; + } + function uncompressData() { if ($this->data !== null)
http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader.php?r1=1.24&r2=1.25&ty=u Index: pear/File_Archive/Archive/Reader.php diff -u pear/File_Archive/Archive/Reader.php:1.24 pear/File_Archive/Archive/Reader.php:1.25 --- pear/File_Archive/Archive/Reader.php:1.24 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader.php Fri May 27 20:58:46 2005 @@ -27,7 +27,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: Reader.php,v 1.24 2005/05/26 21:30:18 vincentlascaux Exp $ + * @version CVS: $Id: Reader.php,v 1.25 2005/05/28 00:58:46 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -199,6 +199,21 @@ } /** + * Move the current position back of a given amount of bytes. + * Not all readers may implement this function (a PEAR error will + * be returned if the reader can't rewind) + * + * @param int $length number of bytes to seek before the current pos + * or -1 to move back to the begining of the current file + * @return the number of bytes really rewinded (which may be less than + * $length if the current pos is less than $length + */ + function rewind($length) + { + return PEAR::raiseError('Rewind function is not implemented on this reader'); + } + + /** * Put back the reader in the state it was before the first call * to next() * @@ -315,6 +330,57 @@ } /** + * Remove the current file from the archive + * After having removed a file from an archive, the current position in the + * archive is set to the next file in the archive + */ + function remove() + { + } + + /** + * Remove some data from the current file in the archive + * After having removed a block of data, the current position in the archive + * is will be after the removed block of data, in the current file that may have + * been moved + * + * @param int $seek Relative position of the begining of the block that must + * be removed, from the current pos + * @param int $size Size of the block (in bytes) to remove, or -1 to remove to + * the end of the file + */ + function removeBlock($seek = 0, $size = -1) + { + } + + /** + * Create a writer to append files to the archive + * After having called this function, $this will be closed and should no longer be used + * + * @return File_Archive_Writer writer on which you can call newFile to append new files + * in the archive + */ + function makeAppendWriter() + { + $this->skip(-1); + return $this->makeDataWriter(); + } + + /** + * Create a writer to append data to the current file, erasing it from current pos + * After having called this function, $this will be closed and should no longer be used + * The order of the files in the archive may not be preserved + * + * Note: if you won't modify the data of the file, use makeAppendWriter which is way faster + * + * @return File_Archive_Writer writer on which you can call writeData to append data to the + * current file in the archive, or newFile to append files + */ + function makeDataWriter($seek = 0) + { + } + + /** * Returns a writer that will start writing at the current pos in the source * Any data (from current file or any other file) located after current pos * will be erased. http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Ar.php?r1=1.7&r2=1.8&ty=u Index: pear/File_Archive/Archive/Reader/Ar.php diff -u pear/File_Archive/Archive/Reader/Ar.php:1.7 pear/File_Archive/Archive/Reader/Ar.php:1.8 --- pear/File_Archive/Archive/Reader/Ar.php:1.7 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader/Ar.php Fri May 27 20:58:48 2005 @@ -194,6 +194,45 @@ } /** + * @see File_Archive_Reader::skip + */ + function skip($length) + { + if ($length == -1) { + $length = $this->_nbBytesLeft; + } else { + $length = min($length, $this->_nbBytesLeft); + } + if ($length == 0) { + return 0; + } else { + $this->_nbBytesLeft -= $length; + return $this->source->skip($length); + } + } + + /** + * @see File_Archive_Reader::rewind + */ + function rewind($length) + { + if ($length == -1) { + $length = $this->_currentStat[7] - $this->_nbBytesLeft; + } else { + $length = min($length, $this->_currentStat[7] - $this->_nbBytesLeft); + } + if ($length == 0) { + return 0; + } else { + $rewinded = $this->source->rewind($length); + if (!PEAR::isError($rewinded)) { + $this->_nbBytesLeft += $rewinded; + } + return $rewinded; + } + } + + /** * @see File_Archive_Reader::makeWriter */ function makeWriter($seek = 0, $fileModif = true) http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Bzip2.php?r1=1.11&r2=1.12&ty=u Index: pear/File_Archive/Archive/Reader/Bzip2.php diff -u pear/File_Archive/Archive/Reader/Bzip2.php:1.11 pear/File_Archive/Archive/Reader/Bzip2.php:1.12 --- pear/File_Archive/Archive/Reader/Bzip2.php:1.11 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader/Bzip2.php Fri May 27 20:58:48 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: Bzip2.php,v 1.11 2005/05/26 21:30:18 vincentlascaux Exp $ + * @version CVS: $Id: Bzip2.php,v 1.12 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -134,6 +134,15 @@ } /** + * @see File_Archive_Reader::rewind + */ + function rewind($length) + { + //TODO: implement rewind + return parent::rewind($length); + } + + /** * @see File_Archive_Reader::makeWriter */ function makeWriter($fileModif = true, $seek = 0) http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Concat.php?r1=1.12&r2=1.13&ty=u Index: pear/File_Archive/Archive/Reader/Concat.php diff -u pear/File_Archive/Archive/Reader/Concat.php:1.12 pear/File_Archive/Archive/Reader/Concat.php:1.13 --- pear/File_Archive/Archive/Reader/Concat.php:1.12 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader/Concat.php Fri May 27 20:58:48 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: Concat.php,v 1.12 2005/05/26 21:30:18 vincentlascaux Exp $ + * @version CVS: $Id: Concat.php,v 1.13 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -146,6 +146,14 @@ return $skipped; } /** + * @see File_Archive_Reader::rewind() + */ + function rewind($length) + { + //TODO: implement rewind + return parent::rewind($length); + } + /** * @see File_Archive_Reader::close() */ function close() http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/File.php?r1=1.18&r2=1.19&ty=u Index: pear/File_Archive/Archive/Reader/File.php diff -u pear/File_Archive/Archive/Reader/File.php:1.18 pear/File_Archive/Archive/Reader/File.php:1.19 --- pear/File_Archive/Archive/Reader/File.php:1.18 Thu May 26 11:57:37 2005 +++ pear/File_Archive/Archive/Reader/File.php Fri May 27 20:58:48 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: File.php,v 1.18 2005/05/26 15:57:37 vincentlascaux Exp $ + * @version CVS: $Id: File.php,v 1.19 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -168,13 +168,15 @@ } } } + /** - * @see File_Archive_Reader::Skip() + * @see File_Archive_Reader::skip() */ function skip($length) { $before = ftell($this->handle); - if (@fseek($this->handle, $length, SEEK_CUR) === -1) { + if (($length == -1 && @fseek($this->handle, 0, SEEK_END) === -1) || + ($length >= 0 && @fseek($this->handle, $length, SEEK_CUR) === -1)) { return parent::skip($length); } else { return ftell($this->handle) - $before; @@ -182,6 +184,20 @@ } /** + * @see File_Archive_Reader::rewind + */ + function rewind($length) + { + $before = ftell($this->handle); + if (($length == -1 && @fseek($this->handle, 0, SEEK_SET) === -1) || + ($length >= 0 && @fseek($this->handle, -$length, SEEK_CUR) === -1)) { + return parent::rewind($length); + } else { + return $before - ftell($this->handle); + } + } + + /** * @see File_Archive_Reader::makeWriter */ function makeWriter($fileModif = true, $seek = 0) http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Gzip.php?r1=1.20&r2=1.21&ty=u Index: pear/File_Archive/Archive/Reader/Gzip.php diff -u pear/File_Archive/Archive/Reader/Gzip.php:1.20 pear/File_Archive/Archive/Reader/Gzip.php:1.21 --- pear/File_Archive/Archive/Reader/Gzip.php:1.20 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader/Gzip.php Fri May 27 20:58:48 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: Gzip.php,v 1.20 2005/05/26 21:30:18 vincentlascaux Exp $ + * @version CVS: $Id: Gzip.php,v 1.21 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -38,6 +38,7 @@ class File_Archive_Reader_Gzip extends File_Archive_Reader_Archive { var $nbRead = 0; + var $filePos = 0; var $gzfile = null; var $tmpName = null; @@ -54,6 +55,7 @@ } $this->nbRead = 0; + $this->filePos = 0; $this->gzfile = null; $this->tmpName = null; @@ -70,6 +72,7 @@ } $this->nbRead++; + $this->filePos = 0; if ($this->nbRead > 1) { return false; } @@ -93,6 +96,7 @@ return true; } + /** * Return the name of the single file contained in the archive * deduced from the name of the archive (the extension is removed) @@ -113,6 +117,7 @@ return $name; } + /** * @see File_Archive_Reader::getData() */ @@ -122,7 +127,7 @@ $data = ''; do { - $newData = gzread($this->gzfile, 8196); + $newData = gzread($this->gzfile, 8192); $data .= $newData; } while ($newData != ''); } else if ($length == 0) { @@ -131,10 +136,57 @@ $data = gzread($this->gzfile, $length); } + $this->filePos += strlen($data); return $data == '' ? null : $data; } /** + * @see File_Archive_Reader::skip() + */ + function skip($length) + { + if($length == -1) { + do + { + $tmp = gzread($this->gzfile, 8192); + $this->filePos += strlen($tmp); + } while ($tmp != ''); + } else { + if (@gzseek($this->gzfile, $this->filePos + $length) === -1) { + return parent::skip($length); + } else { + $this->filePos += $length; + return $length; + } + } + } + + /** + * @see File_Archive_Reader::rewind() + */ + function rewind($length) + { + if ($length == -1) { + if (@gzseek($this->gzfile, 0) === -1) { + return parent::rewind($length); + } else { + $tmp = $this->filePos; + $this->filePos = 0; + return $tmp; + } + } else { + $length = min($length, $this->filePos); + if (@gzseek($this->gzfile, $this->filePos - $length) === -1) { + return parent::rewind($length); + } else { + $this->filePos -= $length; + return $length; + } + } + } + + + /** * @see File_Archive_Reader::makeWriter */ function makeWriter($fileModif = true, $seek = 0) http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Memory.php?r1=1.14&r2=1.15&ty=u Index: pear/File_Archive/Archive/Reader/Memory.php diff -u pear/File_Archive/Archive/Reader/Memory.php:1.14 pear/File_Archive/Archive/Reader/Memory.php:1.15 --- pear/File_Archive/Archive/Reader/Memory.php:1.14 Thu May 26 12:12:19 2005 +++ pear/File_Archive/Archive/Reader/Memory.php Fri May 27 20:58:48 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: Memory.php,v 1.14 2005/05/26 16:12:19 vincentlascaux Exp $ + * @version CVS: $Id: Memory.php,v 1.15 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -133,15 +133,37 @@ $this->offset += $actualLength; return $result; } + /** * @see File_Archive_Reader::skip() */ function skip($length) { - $actualLength = min($length, strlen($this->memory) - $this->offset); - $this->offset += $actualLength; - return $actualLength; + if ($length == -1) { + $length = strlen($this->memory) - $this->offset; + } else { + $length = min($length, strlen($this->memory) - $this->offset); + } + $this->offset += $length; + return $length; + } + + /** + * @see File_Archive_Reader::rewind() + */ + function rewind($length) + { + if ($length == -1) { + $tmp = $this->offset; + $this->offset = 0; + return $tmp; + } else { + $length = min($length, $this->offset); + $this->offset -= $length; + return $length; + } } + /** * @see File_Archive_Reader::close() */ http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Relay.php?r1=1.12&r2=1.13&ty=u Index: pear/File_Archive/Archive/Reader/Relay.php diff -u pear/File_Archive/Archive/Reader/Relay.php:1.12 pear/File_Archive/Archive/Reader/Relay.php:1.13 --- pear/File_Archive/Archive/Reader/Relay.php:1.12 Thu May 26 11:57:37 2005 +++ pear/File_Archive/Archive/Reader/Relay.php Fri May 27 20:58:48 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: Relay.php,v 1.12 2005/05/26 15:57:37 vincentlascaux Exp $ + * @version CVS: $Id: Relay.php,v 1.13 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -79,6 +79,10 @@ */ function skip($length) { return $this->source->skip($length); } /** + * @see File_Archive_Reader::rewind() + */ + function rewind($length) { return $this->source->rewind($length); } + /** * @see File_Archive_Reader::close() */ function close() http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Tar.php?r1=1.20&r2=1.21&ty=u Index: pear/File_Archive/Archive/Reader/Tar.php diff -u pear/File_Archive/Archive/Reader/Tar.php:1.20 pear/File_Archive/Archive/Reader/Tar.php:1.21 --- pear/File_Archive/Archive/Reader/Tar.php:1.20 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader/Tar.php Fri May 27 20:58:48 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.20 2005/05/26 21:30:18 vincentlascaux Exp $ + * @version CVS: $Id: Tar.php,v 1.21 2005/05/28 00:58:48 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -71,10 +71,33 @@ */ function skip($length) { - $actualLength = min($this->leftLength, $length); - $error = $this->source->skip($actualLength); - $this->leftLength -= $actualLength; - return $error; + if ($length == -1) { + $length = $this->leftLength; + } else { + $length = min($this->leftLength, $length); + } + $skipped = $this->source->skip($length); + if (!PEAR::isError($skipped)) { + $this->leftLength -= $skipped; + } + return $skipped; + } + + /** + * @see File_Archive_Reader::rewind() + */ + function rewind($length) + { + if ($length == -1) { + $length = $this->currentStat[7] - $this->leftLength; + } else { + $length = min($length, $this->currentStat[7] - $this->leftLength); + } + $rewinded = $this->source->rewind($length); + if (!PEAR::isError($rewinded)) { + $this->leftLength += $rewinded; + } + return $rewinded; } /** http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Zip.php?r1=1.18&r2=1.19&ty=u Index: pear/File_Archive/Archive/Reader/Zip.php diff -u pear/File_Archive/Archive/Reader/Zip.php:1.18 pear/File_Archive/Archive/Reader/Zip.php:1.19 --- pear/File_Archive/Archive/Reader/Zip.php:1.18 Thu May 26 17:30:18 2005 +++ pear/File_Archive/Archive/Reader/Zip.php Fri May 27 20:58:49 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: Zip.php,v 1.18 2005/05/26 21:30:18 vincentlascaux Exp $ + * @version CVS: $Id: Zip.php,v 1.19 2005/05/28 00:58:49 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -215,8 +215,28 @@ */ function skip($length) { - $this->offset = min($this->offset + $length, $this->currentStat[7]); + $before = $this->offset; + if ($length == -1) { + $this->offset = $this->currentStat[7]; + } else { + $this->offset = min($this->offset + $length, $this->currentStat[7]); + } + return $this->offset - $before; } + /** + * @see File_Archive_Reader::rewind() + */ + function rewind($length) + { + $before = $this->offset; + if ($length == -1) { + $this->offset = 0; + } else { + $this->offset = min(0, $this->offset - $length); + } + return before - $this->offset; + } + function uncompressData() { if ($this->data !== null)