/** * Returns an array of entries in a given zip file * * @param io.streams.MemoryOutputStream $this->out * @param string $password * @return [:string] content */ protected function entriesWithContentIn($out, $password = null) { $zip = ZipFile::open(new MemoryInputStream($out->getBytes()))->usingPassword($password); $entries = []; foreach ($zip->entries() as $entry) { $entries[$entry->getName()] = $this->entryContent($entry); } return $entries; }
/** * Fetches a ZIP file * * @param string url * @return io.archive.zip.ZipArchiveReader */ protected function zipballOf($url) { $headers = array(); do { Console::write('>> ', $url, ': '); $response = $this->connectionTo($url, $headers)->get(); switch ($response->statusCode()) { case HttpConstants::STATUS_OK: Console::writeLine('Ok'); return ZipFile::open($response->getInputStream()); case HttpConstants::STATUS_FOUND: case HttpConstants::STATUS_SEE_OTHER: Console::writeLine('Redirect'); $headers['Referer'] = $url; $url = this($response->header('Location'), 0); continue; default: Console::writeLine('Error'); throw new IllegalStateException('Unexpected response for ' . $url . ': ' . $response->toString()); } } while (1); // Unreachable }
/** * Returns an archive reader for a given zip file * * @param string package * @param string name * @return io.archive.zip.ZipArchiveReader */ protected function archiveReaderFor($package, $name) { return ZipFile::open($this->getClass()->getPackage()->getPackage($package)->getResourceAsStream($name . '.zip')->getInputStream()); }
public function zipfile_open() { $this->assertInstanceOf(ZipArchiveReader::class, ZipFile::open(new MemoryInputStream('PK...'))); }