Compression algorithm used in zlib is almost the same as in gzip and zip . What is the difference?

And what have the PNG actually, if you are about the algorithms, and not about the implementation of the same?

Kromster2021-04-30 14:05:42

@KRomster despite the fact that we are still here and about the implementation too. The ZLIB library went from PNG, and the ZLIB format appeared simultaneously with PNG and was first used in PNG (if I understood the whole story correctly)

andreymal2021-04-30 14:05:42
  • Answer # 1


    zip.-format of archives using, as a rule, algorithm
    Deflate.for compression; The zip archive may contain several files that are compressed separately from each other.g
    zip.Squeezes exactly one file (this file can be a TAR archive) and also uses the Deflate algorithm.
    zlib.implements Deflate and used in Zip, Gzip,>
    PNG.And many other applications. 

    format zip.Fil Katz was designed as an open format, but its implementation, PKZip was conditionally free (Shareware). In this file format, files and directory structure are stored, and each file is compressed regardless of other files. Files and directory structure can also be encrypted.

    Zip format supports multiple compression methods:

    0 -The File IS Stored (No Compression)
    1 -The File IS SHRUNK
    2 -The File IS Reduced With Compression Factor 1
    3 -The File IS Reduced With Compression Factor 2
    4 -The File IS Reduced with Compression Factor 3
    5 -The File IS Reduced With Compression Factor 4
    6 -The File Is Imploded
    7 -Reserved for Tokenizing Compression Algorithm
    8 -The File IS Deflated
    9 -Enhanced Deflating Using Deflate64 (TM)
    10 -PKWare Data Compression Library Imploding (Old IBM TERSE)
    11 -reserved by pkware
    12 -File IS Compressed Using Bzip2 Algorithm
    13 -reserved by pkware
    14 -LZMA (EFS)
    15 -reserved by pkware
    16 -reserved by pkware
    17 -reserved by pkware
    18 -File IS Compressed Using IBM TERSE (NEW)
    19 -IBM LZ77 Z Architecture (PFS)
    97 -WavPack Compressed Data
    98 -PPMD ​​Version I, Rev 1

    Methods 1 to 7 are historical and not used. Methods from 9 to 98 are added relatively recently and are used infrequently. The only widespread method is Method 8, Deflate.And to some extent, method 0, which simply stores files without compression. Most zip files with which you will encounter only methods 8 and 0.

    ISO /IEC 21320-1: 2015 Standard for File ContainersIt is a limited ZIP format used in Java (.jar) files, Office Open XML (Microsoft Office .docx, .xlsx, .pptx), Office Document Format (.odt, .ods, .dp) and EPUB (.epub). This standard allows only compression methods 0 and 8, and also has other limitations like lack of encryption or signatures.

    In about 1990Info-Zip Groupwrote tolerated and free implementations utilities zip. and un zip. With the support of compression Deflate and unpacking older formats. This significantly expanded the use of the format. . zip. .

    In the early 90sformat G zip.was designed to replace UNIX utilities

    . Utility
    Squeezed exactly one file and added an extension to the file
    . She used the LZW algorithm, which at that time was protected by patents, which made it difficult to use it. Although some specific implementations of Deflate were patented by Phil Kaitz, the format itself is not protected by patents, so you can write the implementation of Deflate without disrupting patents. Utility
    was conceived as a transparent replacement utility
    and actually can unpack compressed
    OM data.
    When compressed adds an extension
    to the file name.
    uses Deflate compression format that allows you to compress a little better than
    , quickly unpackled and checks the integrity of data using CRC-32. The GZIP format header also allows you to store the source file name and time to change it.


    Squeezes exactly one file, and archives are usually created to compress multiple files with the preservation of attributes and directory structure.
    which were then compressed with
    for getting
    file. So as not to compress everything manually, utility
    had and still has an option to automatically turn on compression using
    ; With advent
    An option was also added to enable GZIP compression and creation
    files. Archives
    shrink better than what
    Since the files are compressed not separately and the GZIP has the ability to work more effectively with redundancy, especially if there are many small files in the archive.
    Widely distributed in UNIX due to its good tolerance, but there are more efficient compression methods, so the archives may meet

    Unlike .tar . . zip. The archives store the file list separately at the end of the file. Taking into account the fact that each file is compressed independently, it allows you to read individual files in the archive without unpacking the entire archive of the entire archive. And archive .tar Must be unpacked and read entirely to even see a list of files in the archive, and it creates difficulties in some situations.

    Soon after the appearance of GZIP, in about the mid-1990s, the same patent problems questioned the free use of image format

    , very widely used on ads (BBS) and World Wide Web (WWW -New Time). So the small group created PNG -image format with compression without loss -to replace GIF. PNG also uses Deflate format for compression. To promote wide use of PNG format, two free libraries were created:lib PNG.implements all functions of PNG format, and zlib.Provides compression and unpacking code for use in LIBPNG and for other applications. ZLIB was adapted from the GZIP code.

    All of the patents mentioned have already expired.

    ZLIB library supports Deflate, as well as three wrapping for deflate flows. These include: no wrapper in general ("raw" deflate), ZLIB wrapper, which is used in PNG data blocks, and GZIP wrapper. The main difference between the ZLIB and GZIP wrappers is that the ZLIB wrapper is more compact: only 6 bytes against at least 18 bytes for GZIP, and the ADLER-32 integrity check is performed faster than the CRC-32 that is used in GZIP. The raw Deflate method is used by the programs that read and write format.

    which works in its own way with DEFLATE data.

    ZLIB library is used very widely, including the implementation of GZIP format; For example, it is used in most browsers and web servers to compress data transmitted to HTTP (the GZIP format is usually used, since with ZLIB format There are some historical difficulties).

    Different implementations of Deflate can compress the same data with different efficacy, as evidenced by the presence of selected compression levels that allow you to choose between compression efficiency and time spent. ZLIB and PKZip are not the only implementation of Deflate. 
    zopfli.Can spend a lot of time to compress data a few percent more efficient than ZLIB. Utility>
    PIGZ.The multi-threaded implementation of GZIP can use ZLIB (compression levels 1-9) or ZOPFLI (compression level 11) and slightly reduces the time spent by compressing large files on multiple processor kernels. 

    Lightly free translation Answerfrom Mark Adler.on ENSO with some additions.