/** * Read a file entry from the file. * * @param int $fileBinaryOffset The offset in the file to start reading from. * * @return FileEntry * * @throws \RuntimeException When the file name length in the dictionary is zero (corrupted dictionary). */ private function readFile($fileBinaryOffset) { $filenameLength = $this->file->readUint32le(); if (0 === $filenameLength) { throw new \RuntimeException('Unnamed file found.'); } $filename = $this->file->read($filenameLength); $fileSizeUncompressed = $this->file->readUint32le(); $timestamp = new \DateTime('@' . $this->file->readUint32le()); $fileSizeCompressed = $this->file->readUint32le(); $crc = $this->file->readUint32le(); $flags = $this->file->readUint32le(); if (0 < ($fileMetadataLength = $this->file->readUint32le())) { $metadata = unserialize($this->file->read($fileMetadataLength)); } $this->file->savePosition(); $this->file->seek($fileBinaryOffset); $content = $this->file->read($fileSizeCompressed); $this->file->loadPosition(); $file = FileEntry::createFromPhar($filename, $fileSizeUncompressed, $fileSizeCompressed, $timestamp, $crc, $flags, isset($metadata) ? $metadata : null, $content); // Ensure the crc is correct and the data can be decompressed. $file->getContent(); $this->phar->addFile($file); return $file; }
/** * Append all the contents from the passed stream reader. * * @param StreamReader $stream The stream to write. * * @return StreamWriter */ public function writeStream(StreamReader $stream) { $stream->savePosition(); while ('' !== ($buffer = $stream->read(1024, true))) { $this->write($buffer); } $stream->loadPosition(); return $this; }