Submodule compress.zstd
The compress.zstd submodule provides the ability to compress and
decompress data using the zstd
algorithm. You can use the zstd compressor as follows:
-
Create a compressor instance using the compress.zstd.new() function:
local zstd_compressor = require('compress.zstd').new()-- or --local zstd_compressor = require('compress').zstd.new()Optionally, you can pass compression options (zstd_opts) specific for
zstd:
code_snippets/compress_zstd.lua
- To compress the specified data, use the compress() method:
code_snippets/compress_zstd.lua
- To decompress data, call decompress():
code_snippets/compress_zstd.lua
Functions | |
|---|---|
Create a | Objects |
A | |
Configuration options of the |
Create a zstd compressor instance.
Parameters:
options(table) —zstdcompression options (see zstd_opts)
Returns
a new zstd compressor instance (see
zstd_compressor)
Return type
userdata
Example
code_snippets/compress_zstd.lua
A compressor instance that exposes the API for compressing and
decompressing data using the zstd algorithm. To create the zstd
compressor, call compress.zstd.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_zstd.lua
method decompress(data)
Decompress the specified data.
data(string) — data to be decompressed
Returns
decompressed data
Return type
string
Example
code_snippets/compress_zstd.lua
: zstd_opts Configuration options of the zstd_compressor. These options can be passed to the compress.zstd.new() function.
Example
code_snippets/compress_zstd.lua
Specifies the zstd 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. For example, you can use level 1
if speed is most important and level 22 if size is most important.
Default: 3
Minimum: -131072
Maximum: 22