Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Deflater and GZip compression

I am currently using java.util.zip.Deflater to compress. Also java.util.zip.GZIPOutputStream can be used for compression. Here I focus on basically byte array compression.
Can any one let me know the difference between these Deflater and GZIPOutputStream. (performancewise..).

like image 712
Débora Avatar asked Jul 11 '14 08:07

Débora


2 Answers

Deflater produces zlib-wrapped deflate compressed data, unless nowrap is true, in which case it produces raw (unwrapped) deflate compressed data.

GZIPOutputStream produces gzip-wrapped deflate data.

deflate is a compressed data format defined in RFC 1951.

zlib is a two-byte header and four-byte trailer that provides compact identification of the stream and integrity checking on the uncompressed data. zlib is described in RFC 1950.

gzip is a 10+ byte header and 8-byte trailer that provides metadata and integrity checking, where the metadata can include a file name, modification date, originating operating system, comment, and extra data. gzip is described in RFC 1952.

There is no difference with respect to performance, other than a few bytes difference in the header and trailer.

like image 185
Mark Adler Avatar answered Sep 19 '22 12:09

Mark Adler


There is a difference in performance as GZIPOutputStream only has one speed/compression ratio setting that is not changeable, while Deflater has ten possible ratios, from fastest+least compressed to slowest+most compressed. Here is a good article with graphs about it.

like image 37
Vadim Yarovoy Avatar answered Sep 18 '22 12:09

Vadim Yarovoy