/** * @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; }
/** * @see File_Archive_Reader::close() */ function close() { $this->currentFilename = null; $this->currentStat = null; $this->compLength = 0; $this->data = null; $this->seekToEnd = 0; $this->files = array(); $this->centralDirectory = null; return parent::close(); }
/** * 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; }
/** * @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; }
/** * @see File_Archive_Reader::rewind() */ function rewind($length = -1) { 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::close() */ function close() { rar_close($this->rarEntry); if ($this->fileReader !== null) { $this->fileReader->close(); } if ($this->rarTmpName !== null) { unlink($this->rarTmpName); } if ($this->entryTmpName !== null) { unlink($this->entryTmpName); } $this->rarFile = null; $this->rarEntry = null; reset($this->rarList); return parent::close(); }
/** * @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; }
/** * @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; }
/** * @see File_Archive_Reader::close() */ function close() { $this->folders = array(); $this->folderIndex = 0; $this->fileIndex = 0; $this->offset = 0; $this->blockOffset = 0; $this->header = null; $this->data = ''; return parent::close(); }