How can I achieve the best, standard ZIP compression?

20

8

I don't care how long it takes to compress, all I want to achieve is two things:

  • The absolute best possible compression ratio
  • Compatibility with standard readers, such as Windows and WinZip

So suggestions such as 7-zip won't be of much use, unless 7-zip is also slightly better at the standard ZIP compression (as opposed to using it's very good .7z format).

Ideally I'm looking for:

  • A recommendation of a piece of software
  • The particular settings for that software that enable the absolute best compression
  • Something that's free

Remember, how long it takes to compress is not an issue!

One last thing - some files might be better compressed with different settings, like the "Word size" or "Dictionary size" - is there a tool that can analyse the files and choose the most appropriate compression ratio, or does WinZip, 7-zip etc. already do that?

Josh Comley

Posted 2010-06-21T09:21:37.573

Reputation: 3 582

Answers

22

If you want compatibility with the Zip Folders capability built into Windows XP, you're stuck with Deflate compression. I don't think you can even use Deflate64, much less the advanced compression methods (like LZMA, PPMD, WavPack, Bzip2, etc.) available in recent versions of winZip and PowerArchiver. PowerArchiver at least defaults to using the .zipx extension for those files -- I don't think WinZip is doing that yet.

The smallest possible zip file that 7-Zip can create can be done with the following command line:

7za a -mm=Deflate -mfb=258 -mpass=15 -r C:\Path\To\Archive.zip C:\Path\To\Files\*

Of particular note: 7-Zip's wildcard parser is not the same as most others on the system. *.* means all files that have extensions. * means all files.

Creating .zip files this way (and, presumably, using other tools that attempt to make smaller "standard" .zip files) is really, really slow. You would most likely save considerable time and space by using 7-Zip or WinRar to create self extracting archives.

afrazier

Posted 2010-06-21T09:21:37.573

Reputation: 21 316

"much" slower in the previous comment translates to slightly more than 3 times slower. as for space, the slower option gives archive of approx. 99.885 % size compared to the faster (i.e. -mx=9 without -mpass=15) version. So, for 3x more time one can save only 0.115 % of space. So, unless that 0.115% gain is very important, go for -mx=9 instead of -mpass=15. – T.V. – 2019-02-07T00:01:11.357

My 7z error'd on "-m0" but I guess "-mm" does the same with recent versions. I also noticed that, in my case (compressing JPG files), using "-mx9" instead of "-mfb=258 -mpass=15" the result will differ randomly by ±15 bytes on average (with exceptions going in the ±50s) – Mark Jeronimus – 2012-05-01T17:46:13.487

1@Zom-B: You're right, that should have been -mm= instead of -m0=. -m0= is used on .7z archives. Also, the 7-Zip manual specifies that -mx=9 for Zip archives is equivalent to -mfb=128 -mpass=10. What I've noticed is that -mfb=258 -mpass=15 is always much slower than -mx=9 and often doesn't save very much space at all (or occasionally uses a few bytes more). Every once in a while it saves a decent bit of space. – afrazier – 2012-05-01T18:26:24.977

8

The best deflate (the compression format used by standard ZIP) compressors that I know of are:

Deflate file compressed file size comparison from Data compression using Zopfli (archived from original):

╔══════════════╦═══════════╦═════════╦═════════╦═════════╦═════════╗
║              ║Corpus size║gzip ­-9  ║7-­zip    ║kzip     ║Zopfli   ║
╠══════════════╬═══════════╬═════════╬═════════╬═════════╬═════════╣
║Alexa-top-10k ║  693108837║128498665║125599259║125163521║123755118║
║Calgary       ║    3141622║  1017624║   980674║   978993║   974579║
║Canterbury    ║    2818976║   730732║   675163║   674321║   669933║
║enwik8        ║  100000000║ 36445248║ 35102976║ 35025767║ 34995756║
╚══════════════╩═══════════╩═════════╩═════════╩═════════╩═════════╝

Even on random PNGs Zopfli was able to be 0.5% better than pngout. Zopfli makes the smallest of them all.

Anon

Posted 2010-06-21T09:21:37.573

Reputation: 830

How can I use Zopfli to compress a set of files, like with the original zip command? – Panayotis – 2019-07-15T23:09:41.697

1

@Panayotis A Google search for zopfli zip leads to https://github.com/google/zopfli/issues/29 which talks about how the zopfli project won't do Zip files directly but includes discussion of tools like AdvanceCOMP's advzip which can use zopfli as a backend.

– Anon – 2019-07-16T06:08:28.870

5

Assuming you are on Windows: if you still want to use the ZIP format, I would recommend using Ken Silverman's free KZIP command-line utility, found here. Copy it inside the folder containing all the files you need to compress, go to that folder using CMD, and run the following command:

kzip /r <filename of ZIP file> *.*

As Roald suggests, it's best to include the directory where kzip.exe resides in your system's PATH variable to prevent it being included in the archive/Zip file.

So far, I've found the ZIP files created with KZIP is around 10-20% smaller than the ones created by other ZIP compressing programs. They're also fully openable by other archive software (Winzip, WinRAR, 7-zip, etc.) and by Windows.

Isxek

Posted 2010-06-21T09:21:37.573

Reputation: 3 785

5What about not putting it in that directory but somewhere on the PATH of your system? – R-D – 2010-06-21T10:54:52.313

1I had the same requirement - must be supported by Windows standard ZIP functionality. KZIP is what I ended up using as it worked like a champ. Be sure to play with the /s /b /n options to get a good idea of what works best in your environment. – Goyuix – 2010-06-21T14:09:36.933

Of course! The PATH variable. I've edited my answer. Thanks Roald! – Isxek – 2010-06-21T15:56:53.380

or just prefix the command with the path of the executable – micsthepick – 2019-08-27T11:54:34.523

1

Super simple script to compress all folders in a folder to individual zip files using .zip filetype and a Deflate64 compression method.

@echo off
for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X\" -tzip -mx9 -mm=Deflate64

SuperMar1o

Posted 2010-06-21T09:21:37.573

Reputation: 101

-1

It's more a limit of how much memory you have to make available to the compressor while it's doing it's job. Using 7-Zip, I'd pack an archive with .Zip format, Ultra compression, LZMA compression method, and the default 64MB dictionary size. If you have the memory available, then up the dictionary size, though note that you'll need almost 3GB of memory available to compress with a 64MB dictionary. Using a larger dictionary should allow 7-zip to hunt for more matches and provide better compression if you can afford the memory. LZMA beats both gzip (deflate/deflate64, I think) and bzip2 by a good 5% on average, up to 10-12% depending on the content.

I don't know of a tool to find the best word/dictionary size, though I think you'll find that compression method has a stronger correlation with input data, and the average/defaults should be good otherwise.

Darth Android

Posted 2010-06-21T09:21:37.573

Reputation: 35 133

3

I am having some trouble with LZMA - for example, no matter what settings I try in 7zip, the text file in this zip (http://joshz.com/Bad.zip) will not decompress using Windows' built in decompresser (I'm using Windows 7).

– Josh Comley – 2010-06-21T12:28:18.453

(the zip file I linked to contains the erroneous file for reference, but was not compressed with LZMA) – Josh Comley – 2010-06-21T12:29:04.320

@joshcomley I was unable to find a list of supported compression schemes for the built-in windows folder compression tool. According to the Wikipedia for LZMA, it is supported by WinZip and many other compression tools across various platforms, so I elected to go with it. *.zip is just a container format, so I don't know if there is an "official" compression which tools will support, or simply common ones (similar to how *.avi can hold almost any type of video). If you need to ensure it always works, pack it as self-extracting. – Darth Android – 2010-06-21T13:26:47.907

-3

If you are looking for the best compressor for Windows environments, I would recommend you to try either *.zip format with 7-zip LZMA 'Compression Method' OR use 7-Zip *.7z SFX archives . SFX archives have a overhead of about 130 kb over .7z compressed files and are worth using when the size difference between .7z and .zip is large.

Another good but uncommon competitor is the NSIS which can use LZMA compression mode to create highly customizable exes. I know NSIS is not an compressor but a Scripting language but I was impressed it performed better than 7-zip SFX.

A Test I did with 2 files -

  • AutoHotkey-H.exe (946 kb)
  • AutoHotkey.dll (1003 kb)
  • Total Size - 1955 kb

  • 7-Zip .zip - 794 kb
  • 7-Zip .7z SFX - 594 kb
  • NSIS LZMA Solid Compression - 552 kb
  • 7-Zip .7z - 461 kb

As #4 is not what you want, the clear winner is NSIS but for practical reasons, I suggest going with .zip is compressed size is less than 500 kbs and if larger, go with a exe making tool such as 7-Zip SFX or NSIS (7-zip in particular as it is easy to set up).

Avi

Posted 2010-06-21T09:21:37.573

Reputation: 242

2The requirements in the question specifically exclude 7z and other formats. – Bob – 2013-12-14T07:07:20.990

@Bob He said a compressor that is compatible with Windows and exe (my #2 and #3) is. The 7z is only #4 which I have pointed out. – Avi – 2013-12-14T07:24:22.423