compress Module
Note:
The import compress command cannot be used to directly import the compressed module. Otherwise, the error message "error: can not find package'compress'" is displayed during compilation. You are advised to import the compress subpackage to use the compress module.
compress Function Description
The compress module provides compression and decompression functions.
Compression means that data is represented by using fewer bits, so that the data is stored and transmitted more efficiently. In practice, compression is widely used in file compression, web page compression, database backup, and the like.
The implementation of the compression function depends on the compression algorithm. Mainstream compression algorithms include deflate, lz77, and lzw. These algorithms can remove redundant information from data or replace redundant information with more compact representations to implement data compression. Currently, this module uses the Huawei-developed deflate algorithm.
Based on the deflate compression algorithm, a header and a tail are added to the compressed data, and the compressed data can be encapsulated in different formats, such as deflate-raw (without encapsulation), gzip, zip, and png. The zip format is applicable to compression and packing of multiple files, and the gzip format supports only one compressed file. Currently, this module supports the deflate-raw and gzip data formats and does not support the file packing function.
In addition, this module supports the setting of compression levels. A higher compression level corresponds to a higher compression ratio and a slower compression speed. Conversely, a lower compression level corresponds to a lower compression ratio and a faster compression speed.
In particular, zlib is a library for implementing the compression function. The zlib package of this module implements the deflate algorithm and supports the deflate-raw and gzip compression formats.
Package List of the compress Module
The compress module provides the following package:
Name | Description |
---|---|
zlib | The zlib package provides the compression and decompression capabilities. |