Submodule compress.lz4
The compress.lz4 submodule provides the ability to compress and
decompress data using the
lz4
algorithm. You can use the lz4 compressor as follows:
-
Create a compressor instance using the compress.lz4.new() function:
local lz4_compressor = require('compress.lz4').new()-- or --local lz4_compressor = require('compress').lz4.new()Optionally, you can pass compression options (lz4_opts) specific for
lz4:
code_snippets/compress_lz4.lua
- To compress the specified data, use the compress() method:
code_snippets/compress_lz4.lua
- To decompress data, call decompress():
code_snippets/compress_lz4.lua
Functions | |
|---|---|
Create a | Objects |
A | |
Configuration options of the |
Create a lz4 compressor instance.
Parameters:
options(table) —lz4compression options (see lz4_opts)
Returns
a new lz4 compressor instance (see
lz4_compressor)
Return type
userdata
Example
code_snippets/compress_lz4.lua
A compressor instance that exposes the API for compressing and
decompressing data using the lz4 algorithm. To create the lz4
compressor, call compress.lz4.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_lz4.lua
method decompress(data)
Decompress the specified data.
data(string) — data to be decompressed
Returns
decompressed data
Return type
string
Example
code_snippets/compress_lz4.lua
: lz4_opts Configuration options of the lz4_compressor. These options can be passed to the compress.lz4.new() function.
Example
code_snippets/compress_lz4.lua
Specifies the acceleration factor that enables you to adjust the compression ratio and speed. The higher acceleration factor increases the compression speed but decreases the compression ratio.
Default: 1
Maximum: 65537
Minimum: 1
Specifies the decompress buffer size (in bytes). If the size of decompressed data is larger than this value, the compressor returns an error on decompression.
Default: 1048576