Submodule compress.zlib
The compress.zlib submodule provides the ability to compress and
decompress data using the zlib
algorithm. You can use the zlib compressor as follows:
-
Create a compressor instance using the compress.zlib.new() function:
local zlib_compressor = require('compress.zlib').new()-- or --local zlib_compressor = require('compress').zlib.new()Optionally, you can pass compression options (zlib_opts) specific for
zlib:
code_snippets/compress_zlib.lua
- To compress the specified data, use the compress() method:
code_snippets/compress_zlib.lua
- To decompress data, call decompress():
code_snippets/compress_zlib.lua
Functions | |
|---|---|
Create a | Objects |
A | |
Configuration options of the |
Create a zlib compressor instance.
Parameters:
options(table) —zlibcompression options (see zlib_opts)
Returns
a new zlib compressor instance (see
zlib_compressor)
Return type
userdata
Example
code_snippets/compress_zlib.lua
A compressor instance that exposes the API for compressing and
decompressing data using the zlib algorithm. To create the zlib
compressor, call compress.zlib.new().
method compress(data)
Compress the specified data.
Parameters:
data(string) — data to be compressed
Returns
compressed data
Return type
string
Example
code_snippets/compress_zlib.lua
method decompress(data)
Decompress the specified data.
data(string) — data to be decompressed
Returns
decompressed data
Return type
string
Example
code_snippets/compress_zlib.lua
Configuration options of the zlib_compressor. These options can be passed to the compress.zlib.new() function.
Example
code_snippets/compress_zlib.lua
Specifies the zlib compression level that enables you to adjust the
compression ratio and speed. The lower level improves the compression
speed at the cost of compression ratio.
Default: 6
Minimum: 0 (no compression)
Maximum: 9
Specifies how much memory is allocated for the zlib compressor. The
larger value improves the compression speed and ratio.
Default: 8
Minimum: 1
Maximum: 9
Specifies the compression strategy. The possible values:
default- for normal data.huffman_only- forces Huffman encoding only (no string match). The fastest compression algorithm but not very effective in compression for most of the data.filtered- for data produced by a filter or predictor. Filtered data consists mostly of small values with a somewhat random distribution. This compression algorithm is tuned to compress them better.rle- limits match distances to one (run-length encoding).rleis designed to be almost as fast ashuffman_onlybut gives better compression for PNG image data.fixed- prevents the use of dynamic Huffman codes and provides a simpler decoder for special applications.