2
votes

Hi guys I need assistance with the compression levels using zlib. I am trying to code an application for a game which has zlib compression for the files.

I am able to decompress the files without any issues but I cannot recompress the files to the same level. The recompressed files always slightly bigger. I need the compressed files to be either the same size or smaller as the game will not read files which are bigger.

My application is coded in c#. I have tried using zlib.net and also the system.io.compression namespace, but both do not compress the files enough even with the maximum compression specified.

For the System.IO.Compression namespace I am specifying CompressionLevel.Optimal.

For zlib.net I am specifying zlib.zlibConst.Z_BEST_COMPRESSION .

I am attaching the files below, I have included the original file as well as files compressed using zlib.net and system.io.compression.

Thanks for any assistance rendered:

Download the files here: http://www13.zippyshare.com/v/j7EsgTDo/file.html

3
Different implementations will produce different results. This is expected. - nobody

3 Answers

1
votes

I was able to exactly duplicate your 000C_original_file.zlib by compressing the decompressed data with the command line tool gzip -9, and then rewrapping the compressed data by stripping the gzip header and trailer and re-wrapping it with a zlib header and trailer. That is almost certainly how the original was made.

As @usr suggested, you can use Zopfli to recompress instead to get something smaller. I used pigz -11z to compress to the zlib format using Zopfli (compression level 11), where the result was smaller than your original, 3863127 bytes vs. 3942494 for the original.

1
votes

There are tools available on the web to minify ZIP files (and deflate streams). For example there is "Zopfli". If you need to squeeze the last bytes out of a Deflate stream post-process it by using one of these tools. You'll need to use Process.Start to start the minifier tool.

0
votes

It might be worth noting that ZIP/Deflate compression support in the 7Zip application is generally superior to older implementations of Deflate, whilst maintaining compatibility with them (can still decompress with the older versions. Not all implementations of Deflate are equal.

Also note that the classes System.IO.Compression.GZipStream amd DeflateStream implement Deflate without any header data (pure deflate algorithm without without support for any archive format).