javaandroidperformancezipcompression

Inserting already deflated files in a zip file


I have been searching for this issue but I cannot find any response that I can use.

Is it possible (using java) to include new files that are already deflated in a zip file in a way that, after, when I decompress the zip file, those deflated files are inflated in the same way as if they were passed "inflated" to the zip tool and incorporated to the zip as to be compressed ("DEFLETED" in the ZipEntry according to https://docs.oracle.com/javase/8/docs/api/java/util/zip/ZipOutputStream.html#setMethod-int-). In that case, how?

Most of the information about compression with java for zip files I get from google and others searchers can be resumed in:

I deflect the files using JZlib (but you can do with whatever any other library. An example, http://www.avajava.com/tutorials/lessons/how-do-i-deflate-and-inflate-a-file.html)

As you can expect about what I said, when I try to insert the already deflated files, they are deflated again (using the DEFLETED method in the ZipEntry, that is the default) and when the zip file is unzipped, the files are deflated to the their former already deflated state.

Looking to the source of ZipOutputStream.java from oracle, you can see that there are two methods for adding entries to the zip:

    DEFLATED (an integer set to 20)
    STORED   (an integer set to 10)

What I want is to add the deflated entries as STORED in the zip, but once they are added, to change the info in the own zip as if they were processed DEFLATED. Do you know any library or any alternative to do it easily? I was thinking in making my own ZipOutputStream inheriting from the jdk ZipOutputStream and overriding the methods to make the trick, but a "fast copy-paste and modification" of the methods according to this idea -just to have a "it could work" feeling- did not work according to my hopes either.

The reason why I would like to have this option is to compress huge amount of files in a zip file on demand dynamically. I am not sure if this could save time and cpu having the deflated files saved in the database and selecting in each moment those files that are requested to make the zips.

Thanks a lot,


Solution

  • I know this is an outdated thread but looking in to my old folders for cleaning up the disk, I saw a "draft" project I made with this idea for my job. Finally, we discarded it but I have uploaded it to a repo if somebody could be interested in it...

    https://gitlab.com/gylz.mail/dynazip

    It is not even a prototype, just a short example program for showing how this would work. As Mark Adler said, the zip format is not complicated and it is well explained in the link he pointed out in his response.