Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a ZIP Archive without compression? [closed]

Tags:

php

zip

Is there a way to add JPG Files to a ZIP Archive without recompressing them? Sounds weird I know.

Creating a ZIP File via PHP uses lots of CPU. Using ZIP with no comprssion still uses lots of CPU. If I only want to add Images (JPG) to the Archive, why should they be recompressed when the JPGs are already compressed?

I know that every file in a ZIP Archive needs to be in a different Format (compressed) than the original File, but maybe there is a way to only set some headers in front of every file (without recompression) and copy those together to a ZIP Archive.

like image 307
Mike Avatar asked Mar 01 '12 12:03

Mike


2 Answers

Since you have tagged this php, I'll assume that your question applies to the PHP zip extension, in which case the answer is:

No there isn't.

The PHP zip extension does not currently allow you to set the compression method. (The bug has been open for several years and was still unresolved as of Jan 2012).

like image 148
Quentin Avatar answered Oct 29 '22 04:10

Quentin


ZipArchive doesn't allow this (as far as I'm aware, although the extension isn't fully documented in the php.net manual).

However, the PCLZip library does allow a PCLZIP_OPT_NO_COMPRESSION argument when adding a file to a zip.

like image 36
Mark Baker Avatar answered Oct 29 '22 03:10

Mark Baker