Submodule compress.zstd¶
Overview¶
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
:local zstd_compressor = require('compress.zstd').new({ level = 5 })
To compress the specified data, use the compress() method:
compressed_data = zstd_compressor:compress('Hello world!')
To decompress data, call decompress():
decompressed_data = zstd_compressor:decompress(compressed_data)
API Reference¶
Functions |
|
Create a |
|
Objects |
|
A |
|
Configuration options of the |
compress.zstd.new()¶
- new([zstd_opts])¶
Create a
zstd
compressor instance.- Параметры
options (table) –
zstd
compression options (see zstd_opts)- Результат
a new
zstd
compressor instance (see zstd_compressor)- Тип результата
userdata
Example
local zstd_compressor = require('compress.zstd').new({ level = 5 })
zstd_compressor¶
- class zstd_compressor¶
A compressor instance that exposes the API for compressing and decompressing data using the
zstd
algorithm. To create thezstd
compressor, call compress.zstd.new().- compress(data)¶
Compress the specified data.
- Параметры
data (string) – data to be compressed
- Результат
compressed data
- Тип результата
string
Example
compressed_data = zstd_compressor:compress('Hello world!')
- decompress(data)¶
Decompress the specified data.
- Параметры
data (string) – data to be decompressed
- Результат
decompressed data
- Тип результата
string
Example
decompressed_data = zstd_compressor:decompress(compressed_data)
zstd_opts¶
- class zstd_opts¶
Configuration options of the zstd_compressor. These options can be passed to the compress.zstd.new() function.
Example
local zstd_compressor = require('compress.zstd').new({ level = 5 })
- level¶
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: 3Minimum: -131072Maximum: 22Примечание
Assigning 0 to
level
resets its value to the default (3).