Example #1
0
 /**
  * Retrieve the list of the entries contained in this CHM.
  *
  * @throws Exception Throws an Exception in case of errors.
  *
  * @return Entry[]
  */
 protected function retrieveEntryList()
 {
     $result = array();
     $chunkOffset = $this->itsf->getDirectoryOffset() + $this->itsp->getHeaderLength();
     $chunkSize = $this->itsp->getDirectoryChunkSize();
     for ($i = $this->itsp->getFirstPMGLChunkNumber(), $l = $this->itsp->getLastPMGLChunkNumber(); $i <= $l; ++$i) {
         $offset = $chunkOffset + $i * $chunkSize;
         $this->reader->setPosition($offset);
         try {
             $pmgl = new Header\PMGL($this->reader);
         } catch (UnexpectedHeaderException $x) {
             if ($x->getFoundHeader() !== 'PMGI') {
                 throw $x;
             }
             $this->reader->setPosition($offset);
             $pmgi = new Header\PMGI($this->reader);
             $pmgl = null;
         }
         if ($pmgl !== null) {
             $end = $offset + $chunkSize - $pmgl->getFreeSpace();
             $cur = $this->reader->getPosition();
             while ($cur < $end) {
                 $this->reader->setPosition($cur);
                 $entry = new Entry($this);
                 $result[$entry->getPath()] = $entry;
                 $cur = $this->reader->getPosition();
             }
         }
     }
     return $result;
 }
Example #2
0
 /**
  * Initializes the instance.
  *
  * @param Reader $reader The reader that provides the data.
  *
  * @throws UnexpectedHeaderException Throws an UnexpectedHeaderException if the header signature is not valid.
  * @throws Exception Throws an Exception in case of errors.
  */
 public function __construct(Reader $reader)
 {
     $size = $reader->readUInt32();
     if ($size < 6) {
         throw new Exception('The LZXC entry is too small');
     }
     parent::__construct($reader);
     if ($this->headerSignature !== 'LZXC') {
         throw UnexpectedHeaderException::create('LZXC', $this->headerSignature);
     }
     $this->version = $reader->readUInt32();
     if ($this->version !== 2) {
         throw new Exception("Unsupported LZXC header version: {$this->version}");
     }
     $this->resetInterval = $reader->readUInt32();
     $this->windowSize = $reader->readUInt32();
     $this->cacheSize = $reader->readUInt32();
 }
Example #3
0
 /**
  * Initialize the instance.
  *
  * @param Reader $reader The reader that provides the data.
  *
  * @throws \Exception Throws an Exception in case of errors.
  */
 public function __construct(Reader $reader)
 {
     $this->headerSignature = $reader->readString(4);
 }