ZipStream-PHP
ZipStream-PHP copied to clipboard
Disable compression when using `addFileFromStream()`.
Description of the problem
Is there a particular reason this library does not support zero compression (STORE) when reading files from a stream?
I would like to see this feature because I suspect this would reduce the CPU load when packaging very large files. I'd be more than happy to contribute code if I can get some directions for adding this feature.
Example code
<?php
require '../vendor/autoload.php';
$files = [
'data.csv' => __DIR__ . '/files/2013/data.csv', // 2.5GB
'dictionary.pdf' => __DIR__ . '/files/2013/dictionary.pdf', // 2MB
'methodology.pdf' => __DIR__ . '/files/2013/methodology.pdf', // 5MB
];
$options = new ZipStream\Option\Archive();
$options->setSendHttpHeaders(true);
$zip = new ZipStream\ZipStream('data-2013.zip', $options);
foreach ($files as $zipPath => $serverPath) {
if ($streamRead = fopen($serverPath, 'r')) {
$zip->addFileFromStream($zipPath, $streamRead); // This will compress my files no matter what.
}
}
// finish the zip stream
$zip->finish();
Information
- ZipStream-PHP version: 2.1
- PHP version: 7.2
I was reading through the issues, but isn't this exactly what is used in the example of #163?
$options = new \ZipStream\Option\File();
// Turned off deflate
$options->setMethod(\ZipStream\Option\Method::STORE());
$zip->addFileFromStream($imageProperty->fileName, $streamRead, $options);
That seems to me the case as well. At least this file store method did the trick for me.
Tracked via https://github.com/maennchen/ZipStream-PHP/pull/224