Re: Difference between gzip, zip, deflate

On Jul 2, 5:57 pm, "ying...@xxxxxxxxx" <ying...@xxxxxxxxx> wrote:
Can you please help me understand what are the differences between
gzip, zip, deflate?

Deflate is a compression method and compressed data format. It can be
called a "raw" compressed data format, since there is no additional
information in a deflate stream such as file names, lengths, check
values, etc. There are not even magic bytes at the start so you can
recognize it as a deflate stream. It is simply the encoding of a
string of bytes. The deflate format is self-terminating, so when
decoding, you know when to stop without having an input length.

gzip is a wrapper for the deflate format. It provides those missing
items mentioned, such as magic bytes, file name, modification time,
and check values with header and trailer bytes around a deflate
stream. Currently gzip only allows the deflate compression method.
Only one deflate stream can be present in a gzip stream, and so
effectively can represent only one file.

zip is an archive format that contains much more information than a
gzip stream, and allows storing multiple files in an archive. The
format contains path information as well as file names, more file
attribute information, and a central directory to facilitate random
access of the archive. The zip format allows many compressed data
formats, of which deflate is only one (though the most popular for

You didn't mention zlib, but it is another wrapper around deflate
data, as well as the name of a software library for encoding and
decode deflate, zlib, and gzip streams. The zlib wrapper format is
spartan consisting of only six bytes total, and provides magic bytes,
the compression method (only deflate is allowed currently, like gzip),
and a check value at the end.

There are other formats that incorporate deflate and/or zlib formatted
data, such as the PNG image format and the PDF document format.

These formats are all mutually incompatible. However you can write
software to attempt to detect the format and extract the compressed
data. zlib can be used for the deflate decoding, though that only
covers one possible compression format in zip files.

Mark Adler