You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
It would be great to have a function to extract files to a stream instead of a directory. At the moment, I'm calling openFromStream to read my zip archive and then calling extractTo to extract all the files to a temporary directory. Next, I'm using a foreach-loop to iterate through the files and send them back to another stream. So writing / extracting them to the local disk is completely unnecessary since I want to read the zip archive from a stream, use a foreach loop to iterate over all entries and extract each file to a stream.
Example
$zipfile = new \PhpZip\ZipFile();
$zipfile->openFromStream($myRemoteStream);
foreach ($zipfileas$entryName) {
$stream = openStream();
// Extract the content of $entryName to the given stream...$zipfile->extractTo($stream, $entryName);
close($stream);
}
$zipfile->close();
The text was updated successfully, but these errors were encountered:
// This is optional: Create a ZIP file as stream$zipStream = fopen('php://temp', 'ab');
fwrite($zipStream, base64_decode('UEsFBgAAAAAAAAAAAAAAAAAAAAAAAA=='));
$zip = new \PhpZip\ZipFile();
$zip->openFromStream($zipStream);
$zip->addFromString('example.txt', 'my content');
$zip->addFromString('sub1/example2.txt', 'my content2');
$listFiles = $zip->getListFiles();
foreach ($listFilesas$entryName) {
// Extract the content of $entryName to the given stream$stream = $zip->getEntryStream($entryName);
// Optional: Convert stream to string$content = stream_get_contents($stream);
fclose($stream);
}
$zip->close();
Description
It would be great to have a function to extract files to a stream instead of a directory. At the moment, I'm calling
openFromStream
to read my zip archive and then callingextractTo
to extract all the files to a temporary directory. Next, I'm using a foreach-loop to iterate through the files and send them back to another stream. So writing / extracting them to the local disk is completely unnecessary since I want to read the zip archive from a stream, use a foreach loop to iterate over all entries and extract each file to a stream.Example
The text was updated successfully, but these errors were encountered: