/** * Initializes 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->reader = $reader; $reader->setPosition(0); $this->itsf = new Header\ITSF($reader); if ($this->itsf->getSectionOffset() >= 0 && $this->itsf->getSectionLength() >= 16) { $reader->setPosition($this->itsf->getSectionOffset()); /* Unknown (510) */ $reader->readUInt32(); /* Unknown (0) */ $reader->readUInt32(); $totalLength = $reader->readUInt64(); if ($totalLength !== $reader->getLength()) { throw new Exception("Invalid CHM size: expected length {$totalLength}, current length {$reader->getLength()}"); } } $reader->setPosition($this->itsf->getDirectoryOffset()); $this->itsp = new Header\ITSP($reader); $expectedDirectoryLength = $this->itsf->getDirectoryLength(); $calculatedDirectoryLength = $this->itsp->getHeaderLength() + $this->itsp->getNumberOfDirectoryChunks() * $this->itsp->getDirectoryChunkSize(); if ($expectedDirectoryLength !== $calculatedDirectoryLength) { throw new Exception("Unexpected directory list size (expected: {$expectedDirectoryLength}, calculated: {$calculatedDirectoryLength})"); } $this->sections = array(); $this->sections[0] = new Section\UncompressedSection($this); $this->entries = $this->retrieveEntryList(); $this->retrieveSectionList(); $this->toc = null; $this->index = null; }
/** * 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(); }