/** * 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; }
public function testNoStoreFlag() { $result = []; $this->reader->addListener('years.*.months.*', function ($keys, $value) { return StreamReader::NO_STORE; }); $this->reader->addListener('years.*.months', function ($keys, $value) use(&$result) { $result[] = $value; }); $data = ['years' => ['2014' => ['months' => ['jan' => 'a', 'feb' => 'b', 'mar' => 'c', 'apr' => 'd', 'may' => 'e', 'jun' => 'f', 'jul' => 'g', 'aug' => 'h', 'sep' => 'i', 'oct' => 'j', 'nov' => 'k', 'dec' => 'l']], '2015' => ['months' => ['jan' => 'a', 'feb' => 'b', 'mar' => 'c', 'apr' => 'd', 'may' => 'e', 'jun' => 'f', 'jul' => 'g', 'aug' => 'h', 'sep' => 'i', 'oct' => 'j', 'nov' => 'k', 'dec' => 'l']]]]; $stream = $this->createStream(json_encode($data)); $this->reader->parse($stream); $this->assertEquals([[], []], $result); }
/** * 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; }
static function __static() { self::$GD_USERSTREAMS_BUG = version_compare(PHP_VERSION, '5.5.0RC1', '>=') && version_compare(PHP_VERSION, '5.5.1', '<') && 0 !== strncmp('WIN', PHP_OS, 3); }
/** * Reset the result set * * @return void */ public function rewind() { $this->row = 0; $this->stream->offset($this->offset); }