Is it better to combine existing zip files vs creating new ones?

286 Views Asked by At

I have an app server which has bunch of files and I may need dynamically combine a subset of them during run-time and send them in a single HTTP response as a zipped file. Let's pretend these files are A and B. I can either pre-store them as A.zip and B.zip and combine them into C.zip which has A and B inside them or just store them A and B and zip them up into C.zip. Which one is faster?

1

There are 1 best solutions below

3
On BEST ANSWER

They are both a bad idea. Making C.zip with two files inside, A.zip and B.zip, would be trying to compress largely incompressible files, and would require three decompression steps to extract instead of one. (You can avoid wasting time trying to compress with appropriate options to zip.) Extracting A and B and zipping up a new C throws away all the compression effort that went into making A and B, and repeats all that while making C.

Instead you want to merge the two zip files, assuming that there are no colliding filename/paths therein. You can use zipmerge to combine two zip files.

Update:

Funny, I just remembered that I wrote one of these about a year ago. It is called zipknit.