Submodule compress.lz4 | Tarantool
Документация на русском языке
поддерживается сообществом

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:

  1. 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:

    local lz4_compressor = require('compress.lz4').new({
        acceleration = 1000,
        decompress_buffer_size = 2097152
    })
    
  2. To compress the specified data, use the compress() method:

    compressed_data = lz4_compressor:compress('Hello world!')
    
  3. To decompress data, call decompress():

    decompressed_data = lz4_compressor:decompress(compressed_data)
    

Functions  
compress.lz4.new() Create a lz4 compressor instance.
Objects  
lz4_compressor A lz4 compressor instance.
lz4_opts Configuration options of the lz4 compressor.

compress.lz4.new([lz4_opts])

Create a lz4 compressor instance.

Параметры:
Return:

a new lz4 compressor instance (see lz4_compressor)

Rtype:

userdata

Example

local lz4_compressor = require('compress.lz4').new({
    acceleration = 1000,
    decompress_buffer_size = 2097152
})

object lz4_compressor

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().

lz4_compressor:compress(data)

Compress the specified data.

Параметры:
  • data (string) – data to be compressed
Return:

compressed data

Rtype:

string

Example

compressed_data = lz4_compressor:compress('Hello world!')
lz4_compressor:decompress(data)

Decompress the specified data.

Параметры:
  • data (string) – data to be decompressed
Return:

decompressed data

Rtype:

string

Example

decompressed_data = lz4_compressor:decompress(compressed_data)

object lz4_opts

Configuration options of the lz4_compressor. These options can be passed to the compress.lz4.new() function.

Example

local lz4_compressor = require('compress.lz4').new({
    acceleration = 1000,
    decompress_buffer_size = 2097152
})
lz4_opts.acceleration

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
lz4_opts.decompress_buffer_size

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
Нашли ответ на свой вопрос?
Обратная связь