The following works as expected:
use io\File;
use io\archive\zip\ZipFile;
use io\streams\Streams;
use util\cmd\Console;
$entries= [];
$z= ZipFile::open(new File($argv[1]));
foreach ($z->entries() as $entry) {
if ($entry->isDirectory()) {
// Create dir
} else {
Console::writeLine($entry->getName(), ' (', $entry->getSize(), ' bytes)');
$entries[$entry->getName()]= $entry;
}
}
if ($file= ($argv[2] ?? null)) {
Console::writeLine($file, ' => `', Streams::readAll($entries[$file]->in()), '`');
}
However, if the script above is changed to store the input streams instead of the entry references as follows:
--- unzip.script.php.orig 2026-04-18 11:01:02.939946100 +0200
+++ unzip.script.php 2026-04-18 11:01:09.531390500 +0200
@@ -12,10 +12,10 @@
// Create dir
} else {
Console::writeLine($entry->getName(), ' (', $entry->getSize(), ' bytes)');
- $entries[$entry->getName()]= $entry;
+ $entries[$entry->getName()]= $entry->in();
}
}
if ($file= ($argv[2] ?? null)) {
- Console::writeLine($file, ' => `', Streams::readAll($entries[$file]->in()), '`');
+ Console::writeLine($file, ' => `', Streams::readAll($entries[$file]), '`');
}
...reading the file contents yields the bytes \024\v\n\000 instead of the file content.
The following works as expected:
However, if the script above is changed to store the input streams instead of the entry references as follows:
...reading the file contents yields the bytes
\024\v\n\000instead of the file content.