google / zopfli

Zopfli Compression Algorithm is a compression library programmed in C to perform very good, but slow, deflate or zlib compression.
Apache License 2.0
3.42k stars 326 forks source link

How to use zopfli DEFLATE in zip archive? #29

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi!
I was wondering if anyone could lend any guidance for how one could use zopfli 
to (re)compress a zip file? I'd like to use it to repack jar files, but I don't 
know of any way to combine the zopfli raw output with the proper headers.

libarchive's bsdtar can produce zip files and use an external compression 
program, but it expects the program to be able to stream from stdin to stdout I 
think.

I tried creating a wrapper (lets call it zopflinout):

#!/bin/sh
zopfli /dev/stdin --deflate -c

... and using

bsdtar -cv --format zip --use-compress-program zopflinout foo.zip *

... but this quickly segfaults and tells me 'Can't write to filter.'

Also (not really related, but...) here is a patch for the makefile to:

- Allow for environmental overrides for compiler variables.
- Build a static library.
- Build a shared library on Darwin.
- Use LDFLAGS.
- Actually use CXXFLAGS when building zopflipng (you have a variable for it but 
don't use it in the target).

... if you want?

Original issue reported on code.google.com by bathtub...@gmail.com on 1 Nov 2013 at 9:26

Attachments:

GoogleCodeExporter commented 9 years ago
https://code.google.com/p/zopfli/issues/detail?id=31

Original comment by alex.hel...@gmail.com on 18 Jan 2014 at 3:29

GoogleCodeExporter commented 9 years ago
I agree that Zopfli ought to have .ZIP file support. Currently, when running it 
as a command-line utility, it says that it can output as Gzip format (default), 
DEFLATE format, or ZLib format. So currently, you can use it to (re)compress 
.tar.gz archives, by decompressing them back to .tar archives and then using 
Zopfli to compress to .tar.gz. However, Zopfli doesn't support outputting in 
.ZIP format (although standard PKzip2/InfoZip compatible .ZIP files do use the 
DEFLATE compression codec). Many other types of files, like .JAR files used by 
Java, the OpenDocument files used by MS Office 2007 and later, and many many 
others, are actually renamed .ZIP files. So adding support for (re)compressing 
.ZIP files would allow (re)compressing Java .JAR files, MS Office OpenDocument 
files, and many others.

So my idea for .ZIP support is to add ZIP as a possible output format, and 
either allow for inputting multiple files and/or directories (which would 
require being able to process wildcards and recursively going through 
subdirectories), or, alternatively, inputting a single .ZIP or .TAR or .TAR.GZ 
or whichever format is easiest, and compressing it into a new .ZIP file as the 
output.

Also I don't quite understand how it is supposed to work on .PNG files (if at 
all). The only files I seem to be able to get it to work on (with the 
command-line version) are .gz files, .tar.gz files, and so on. Anyway, I don't 
have any patches to submit to implement this, this is just a feature 
request/help request that is pretty similar to the above one, which is why I'm 
adding it as a comment instead of as a separate bug report. Any comment by the 
developers of Zopfli on how it can be used to implement .ZIP archive format 
compression would also be appreciated (as would implementing said .ZIP support 
in Zopfli's command-line tool).

Original comment by omi...@gmail.com on 15 Feb 2014 at 7:44

GoogleCodeExporter commented 9 years ago
Gzip is implemented because it is a header of a few bytes around DEFLATE. The 
.ZIP file format uses DEFLATE too but has a lot of features: multiple files, 
directories, encryption, ... that require a dedicated encoder/decoder.

So to implement .ZIP, an existing or new zip encoder can use Zopfli's DEFLATE 
as its compression backend. It's out of scope to implement it here now though.

For PNG, the same is possible: using Zopfli as the DEFLATE/gzip backend of a 
PNG encoder. This has been done several times, including in the repository of 
Zopfli itself 
(https://code.google.com/p/zopfli/source/browse/#git%2Fsrc%2Fzopflipng) as well 
as projects which use other PNG optimizers combined with Zopfli.

Original comment by lode.van...@gmail.com on 30 Jun 2014 at 4:07

GoogleCodeExporter commented 9 years ago
afaict pigz supports zopfli for zip files

Original comment by alex.hel...@gmail.com on 1 Jul 2014 at 11:05

GoogleCodeExporter commented 9 years ago
AdvanceCOMP can recompress ZIP files with Zopfli like this:

# advzip --recompress -4 --iter 100 my.jar

http://advancemame.sourceforge.net/doc-advzip.html

Original comment by dajhorn@vanadac.com on 13 Jul 2014 at 3:36