Tarantool CE/EE Documentation portal logo
Support
Updated at July 17, 2026   02:08 PM

Submodule compress.zlib

Overview

The compress.zlib submodule provides the ability to compress and decompress data using the zlib algorithm. You can use the zlib compressor as follows:

  1. 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
  1. To compress the specified data, use the compress() method:
code_snippets/compress_zlib.lua
  1. To decompress data, call decompress():
code_snippets/compress_zlib.lua

API Reference

Functions

compress.zlib.new()

Create a zlib compressor instance.

Objects

zlib_compressor

A zlib compressor instance.

zlib_opts

Configuration options of the zlib compressor.

compress.zlib.new()

new([zlib_opts])

Create a zlib compressor instance.

Parameters:

  • options (table) — zlib compression options (see zlib_opts)

Returns

a new zlib compressor instance (see zlib_compressor)

Return type

userdata

Example

code_snippets/compress_zlib.lua

zlib_compressor

zlib_compressor

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

zlib_opts

zlib_opts

Configuration options of the zlib_compressor. These options can be passed to the compress.zlib.new() function.

Example

code_snippets/compress_zlib.lua

level

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

mem_level

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

strategy

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). rle is designed to be almost as fast as huffman_only but gives better compression for PNG image data.
  • fixed - prevents the use of dynamic Huffman codes and provides a simpler decoder for special applications.