Exemple #1
0
 /**
  * @see File_Archive_Reader::next()
  */
 function next()
 {
     if (!parent::next()) {
         return false;
     }
     $this->nbRead++;
     if ($this->nbRead > 1) {
         return false;
     }
     $dataFilename = $this->source->getDataFilename();
     if ($dataFilename !== null) {
         $this->tmpName = null;
         $this->bzfile = @bzopen($dataFilename, 'r');
         if ($this->bzfile === false) {
             return PEAR::raiseError("bzopen failed to open {$dataFilename}");
         }
     } else {
         $this->tmpName = tempnam(File_Archive::getOption('tmpDirectory'), 'far');
         //Generate the tmp data
         $dest = new File_Archive_Writer_Files();
         $dest->newFile($this->tmpName);
         $this->source->sendData($dest);
         $dest->close();
         $this->bzfile = bzopen($this->tmpName, 'r');
     }
     return true;
 }
Exemple #2
0
 /**
  * @see File_Archive_Reader::next()
  */
 function next()
 {
     if (!parent::next()) {
         return false;
     }
     $this->nbRead++;
     $this->filePos = 0;
     if ($this->nbRead > 1) {
         return false;
     }
     $dataFilename = $this->source->getDataFilename();
     if ($dataFilename !== null) {
         $this->tmpName = null;
         $this->gzfile = gzopen($dataFilename, 'r');
     } else {
         $this->tmpName = tempnam(File_Archive::getOption('tmpDirectory'), 'far');
         //Generate the tmp data
         $dest = new File_Archive_Writer_Files();
         $dest->newFile($this->tmpName);
         $this->source->sendData($dest);
         $dest->close();
         $this->gzfile = gzopen($this->tmpName, 'r');
     }
     return true;
 }
Exemple #3
0
 /**
  * @see File_Archive_Reader::next()
  */
 function next()
 {
     $error = parent::next();
     if (PEAR::isError($error)) {
         return $error;
     }
     if ($this->header === null) {
         $error = $this->_readHeader();
         if (PEAR::isError($error)) {
             return $error;
         }
         return !empty($this->folders);
     } else {
         $error = $this->skip();
         if (PEAR::isError($error)) {
             return $error;
         }
         $this->fileIndex++;
         $this->blockOffset = 0;
         if ($this->fileIndex >= count($this->folders[$this->folderIndex]['files'])) {
             $this->offset = 0;
             $this->folderIndex++;
             if ($this->folderIndex >= count($this->folders)) {
                 return false;
             }
         }
         return true;
     }
 }
Exemple #4
0
 /**
  * @see File_Archive_Reader::next()
  */
 function next()
 {
     $error = parent::next();
     if (PEAR::isError($error)) {
         return $error;
     }
     if ($this->rarFile === null) {
         $dataFilename = $this->source->getDataFilename();
         if ($dataFilename !== null) {
             $this->rarTmpName = null;
             $this->rarFile = rar_open($dataFilename);
         } else {
             $this->rarTmpName = tempnam(File_Archive::getOption('tmpDirectory'), 'far');
             //Generate the tmp data
             $dest = new File_Archive_Writer_Files();
             $dest->newFile($this->tmpName);
             $this->source->sendData($dest);
             $dest->close();
             $this->rarFile = rar_open($this->tmpName);
         }
         if (!$this->rarFile) {
             return PEAR::raiseError("Unable to open rar file {$dataFilename}");
         }
         if ($this->rarList === null) {
             $this->rarList = rar_list($this->rarFile);
             reset($this->rarList);
         }
     }
     if ($fileReader !== null) {
         $this->fileReader->close();
         $this->fileReader = null;
     }
     $entryName = next($this->rarList);
     $this->source = null;
     if ($entryName === false) {
         return false;
     }
     $this->rarEntry = rar_entry_get($this->rarFile, $entryName);
     if (!$this->rarEntry) {
         return PEAR::raiseError("Error reading entry {$entryName}");
     }
     return true;
 }
Exemple #5
0
 /**
  * Go to next file entry in ZIP archive
  * This function will not stop on a folder entry
  * @see File_Archive_Reader::next()
  */
 function next()
 {
     if (!parent::next()) {
         return false;
     }
     do {
         $result = $this->nextWithFolders();
         if ($result !== true) {
             return $result;
         }
     } while (substr($this->getFilename(), -1) == '/');
     return true;
 }
Exemple #6
0
 /**
  * @see File_Archive_Reader::next()
  */
 function next()
 {
     $error = parent::next();
     if ($error !== true) {
         return $error;
     }
     if ($this->seekToEnd !== null) {
         return false;
     }
     do {
         $error = $this->source->skip($this->leftLength + $this->footerLength);
         if (PEAR::isError($error)) {
             return $error;
         }
         $rawHeader = $this->source->getData(512);
         if (PEAR::isError($rawHeader)) {
             return $rawHeader;
         }
         if (strlen($rawHeader) < 512 || $rawHeader == pack("a512", "")) {
             $this->seekToEnd = strlen($rawHeader);
             $this->currentFilename = null;
             return false;
         }
         $header = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" . "a8checksum/a1type/a100linkname/a6magic/a2version/" . "a32uname/a32gname/a8devmajor/a8devminor/a155prefix", $rawHeader);
         $this->currentStat = array(2 => octdec($header['mode']), 4 => octdec($header['uid']), 5 => octdec($header['gid']), 7 => octdec($header['size']), 9 => octdec($header['mtime']));
         $this->currentStat['mode'] = $this->currentStat[2];
         $this->currentStat['uid'] = $this->currentStat[4];
         $this->currentStat['gid'] = $this->currentStat[5];
         $this->currentStat['size'] = $this->currentStat[7];
         $this->currentStat['mtime'] = $this->currentStat[9];
         if ($header['magic'] == 'ustar') {
             $this->currentFilename = $this->getStandardURL($header['prefix'] . $header['filename']);
         } else {
             $this->currentFilename = $this->getStandardURL($header['filename']);
         }
         $this->leftLength = $this->currentStat[7];
         if ($this->leftLength % 512 == 0) {
             $this->footerLength = 0;
         } else {
             $this->footerLength = 512 - $this->leftLength % 512;
         }
         $checksum = 8 * ord(" ");
         for ($i = 0; $i < 148; $i++) {
             $checksum += ord($rawHeader[$i]);
         }
         for ($i = 156; $i < 512; $i++) {
             $checksum += ord($rawHeader[$i]);
         }
         if (octdec($header['checksum']) != $checksum) {
             die('Checksum error on entry ' . $this->currentFilename);
         }
     } while ($header['type'] != 0);
     return true;
 }
Exemple #7
0
 /**
  * @see File_Archive_Reader::next()
  */
 function next()
 {
     $error = parent::next();
     if ($error !== true) {
         return $error;
     }
     $this->source->skip($this->_nbBytesLeft + ($this->_footer ? 1 : 0));
     $filename = $this->source->getDataFilename();
     if (!$this->_alreadyRead) {
         $header = $this->source->getData(8);
         if ($header != "!<arch>\n") {
             return PEAR::raiseError("File {$filename} is not a valid Ar file format (starts with {$header})");
         }
         $this->_alreadyRead = true;
     }
     $name = $this->source->getData(16);
     $mtime = $this->source->getData(12);
     $uid = $this->source->getData(6);
     $gid = $this->source->getData(6);
     $mode = $this->source->getData(8);
     $size = $this->source->getData(10);
     $delim = $this->source->getData(2);
     if ($delim === null) {
         return false;
     }
     // All files inside should have more than 0 bytes of size
     if ($size < 0) {
         return PEAR::raiseError("Files must be at least one byte long");
     }
     $this->_footer = $size % 2 == 1;
     // if the filename starts with a length, then just read the bytes of it
     if (preg_match("/\\#1\\/(\\d+)/", $name, $matches)) {
         $this->_header = 60 + $matches[1];
         $name = $this->source->getData($matches[1]);
         $size -= $matches[1];
     } else {
         // strip trailing spaces in name, so we can distinguish spaces in a filename with padding
         $this->_header = 60;
         $name = preg_replace("/\\s+\$/", "", $name);
     }
     $this->_nbBytesLeft = $size;
     if (empty($name) || empty($mtime) || empty($uid) || empty($gid) || empty($mode) || empty($size)) {
         return PEAR::raiseError("An ar field is empty");
     }
     $this->_currentFilename = $this->getStandardURL($name);
     $this->_currentStat = array(2 => $mode, 'mode' => $mode, 4 => $uid, 'uid' => $uid, 5 => $gid, 'gid' => $gid, 7 => $size, 'size' => $size, 9 => $mtime, 'mtime' => $mtime);
     return true;
 }
Exemple #8
0
 /**
  * @see File_Archive_Reader::next()
  */
 function next()
 {
     $error = parent::next();
     if ($error !== true) {
         return $error;
     }
     if ($this->seekToEnd !== null) {
         return false;
     }
     while (true) {
         //Advance $this
         $header = $this->_nextAdvance();
         if (!$header || PEAR::isError($header)) {
             return $header;
         }
         //Are we looking at a Long Link?
         if ($header['type'] == 'L') {
             //This is a filepath too long for the tar format.
             //So the tar specification puts the name in a special entry just before the real data
             //This means the filename is the current piece of data.  Grab it.
             $filename = '';
             while (($str = $this->getData(256)) !== null) {
                 if (PEAR::isError($str)) {
                     return $str;
                 }
                 $filename .= $str;
             }
             //The actual file data is the next item.  Advance there and set the filename to what we just made.
             //Everything about the "next" item is correct except the file name.
             $header = $this->_nextAdvance();
             if (!$header || PEAR::isError($header)) {
                 return $header;
             }
             $this->currentFilename = $filename;
         }
         /**
          * Note that actions taken above to handle LongLink may have advanced $this and reset some vars.
          * But that just leaves us in a state to actually handle the thing as if it were a normal file.
          * So continue as if this never happened...
          */
         //Other than the above we only care about regular files.
         //NOTE: Any non-numeric type codes will == 0
         //We handle 'L' above, I don't know what others are out there.
         //5 == directory
         if ($header['type'] == 0 || $header['type'] == 5) {
             break;
         }
     }
     return true;
 }