The difference between zlib,gzip,zip,7z compression

Source: Internet
Author: User
Tags mongodb postgresql


Zlib is a data compression library that is designed to handle simple data (regardless of the source of the data).



Gzip is a file compression tool (or the compressed file format produced by the compression tool) that is designed to work with individual files. Gzip uses zlib to compress data in a file. In order to save information about file attributes, Gzip needs to save more header content in a compressed file (*.gz), and zlib do not have to consider this. But Gzip only applies to a single file, so we often see on the unix/linux of the compression packet suffix is *.tar.gz or *.tgz, that is, the first to use tar to package multiple files into a single file, and then use gzip compression results.



Zip is a format for compressing multiple files (the corresponding tools have PKZIP and WinZip, etc.), so the zip file further contains information about the file directory structure, more than Gzip header information. However, note that the ZIP format can use a variety of compression algorithms, most of our common ZIP files are not compressed by the zlib algorithm, its compressed data format and gzip very different.



The Java SDK provides support for the above three compression technologies: the Inflater class and Deflater classes provide support for the GZIP format directly with the Zlib library for data compression/decompression, Gzipinputstream classes, and Gzipoutputstream classes. ZipFile, Zipinputstream, and Zipoutputstream are used to process files in zip format.



Therefore, you should, depending on your specific needs, choose a different compression technology: If you only need to compress/decompress data, you can directly use zlib implementation, if you need to generate GZIP format files or decompression other tools of the compression results, you have to use gzip or zip and other related classes to deal with.



DEFLATE


DEFLATE is a lossless data compression algorithm using the LZ77 algorithm and Huffman coding. It was originally defined by Phil Katz as the second edition of his PKZIP archiving tool and later defined in the RFC1951 specification.



It is generally accepted that DEFLATE is not subject to any patent and that this format is applied in gzip compressed files and PNG image files in addition to being applied in the ZIP file format, prior to the expiration of the patent associated with the LZW (GIF file format).



DEFLATE compression and decompression of the source code can be found in the free, Universal compression library zlib.



The DEFLATE of higher compression rate is realized by 7-zip. This implementation is also used by AdvanceCOMP to compress gzip, PNG, MNG, and ZIP files to achieve smaller file sizes than zlib. In Ken Silverman's Kzip and PNGOut, a DEFLATE program that is more efficient and requires more user input is used.



Inflate



Inflate is a widely used decompression algorithm, such as gzip, PNG, and Linux also uses inflate to extract the kernel. The Inflate decompression algorithm uses a subset of the 3rd fast decompression method, which does not consider long_code, while putting same_ Length is merged into Medium_code. For same_length encoding of rules, such as length and distance encoding, inflate uses additional base and extra representations. This is because when you construct a generic lookup table, although you can not construct a secondary table for the same_length prefix, we need another table to hold the order of the symbols, and the table may have more space. But for length and distance encodings, their order is incremented, so there is no need for extra tables to hold the order of the symbols.



Inflate uses root to represent the above B, the data structure of the lookup table is code. The primary table and the vice are saved in a large array codes[enough in the inflate_state structure. The table's constructor is located in the inftrees.c file's Inflate_ Table.


7z



7z is a new compression format that has the current highest compression ratio.



7z has exposed the structure editing function, so it can support any kind of new compression algorithm. To date, the following compression algorithms have been consolidated into the 7z:



Compression algorithm note Lzma The latest version of LZ77 improved and optimized algorithm PPMD based on the Shkarin algorithm PPMDH and optimized BCJ 32-bit x86 executable file converter BCJ2 32-bit x86 executable file conversion Program BZIP2 standard BWT algorithm Deflate standard lz77-based algorithm


Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.