ZipStream-PHP icon indicating copy to clipboard operation
ZipStream-PHP copied to clipboard

Disable compression when using `addFileFromStream()`.

Open mmenavas opened this issue 5 years ago • 2 comments

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

mmenavas avatar Aug 21 '20 21:08 mmenavas

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);

Neograph734 avatar Oct 18 '20 21:10 Neograph734

That seems to me the case as well. At least this file store method did the trick for me.

pieterdt avatar Jan 18 '21 16:01 pieterdt

Tracked via https://github.com/maennchen/ZipStream-PHP/pull/224

maennchen avatar Nov 25 '22 04:11 maennchen