19 declare(strict_types=1);
42 $this->zip = new \ZipArchive();
43 if (!$this->zip->open($this->stream->getMetadata()[
'uri'], \ZipArchive::RDONLY)) {
44 throw new \InvalidArgumentException(
'Could not open ZIP-File');
50 if ($this->structure !== null) {
55 for ($i = 0; $i < $this->zip->count(); $i++) {
56 $path_original = $this->zip->getNameIndex($i);
57 $path =
'/' . ltrim($path_original,
'./');
61 $dirname = dirname(
$path);
62 $basename = basename($path_original);
63 if (in_array($basename, $this->ignored,
true)) {
67 $is_dir = (substr(
$path, -1) ===
'/' || substr(
$path, -1) ===
'\\');
69 $stats = $this->zip->statIndex($i, \ZipArchive::FL_UNCHANGED);
73 $modified = $modified = (
int) ($stats[
'mtime'] ?? 0);
76 $finfo = finfo_open(FILEINFO_MIME_TYPE);
78 $stream = $this->zip->getStream($path_original);
79 $fread = fread($stream, 256);
80 $mime_type = finfo_buffer($finfo, $fread);
82 $size = (
int) ($stats[
'size'] ?? 0);
85 $mime_type = self::APPLICATION_OCTET_STREAM;
89 $parent = dirname($path_original);
90 $structure[$parent] = [
92 'dirname' => dirname($parent),
93 'basename' => basename($parent),
97 'modified' => $modified,
101 $structure[$path_original] = [
103 'dirname' => $dirname,
104 'basename' => $basename,
106 'mime_type' => $mime_type,
108 'modified' => $modified,
118 public function getItem(
string $path_inside_zip, array $structure = null): array
121 $info = $structure[$path_inside_zip] ?? [];
126 $this->stream->getMetadata()[
'uri'],
130 return [$stream, $info];
__construct(private FileStream $stream)
static ofFileInsideZIP(string $path_to_zip, string $path_inside_zip)
const APPLICATION_OCTET_STREAM
getItem(string $path_inside_zip, array $structure=null)
The base interface for all filesystem streams.