esdb_archive_nif (reckon_db v1.6.0)
View SourceOptimized archive compression for reckon-db.
This module provides high-performance compression implementations:
- LZ4: Fastest compression/decompression (real-time use)
- Zstd: Best compression ratio (cold storage)
- Zlib: Standard compatibility (Erlang term_to_binary)
The mode is automatically detected at startup based on whether the NIF library is available. Community edition users (hex.pm) will always use the Erlang fallbacks, which provide identical functionality.
Algorithm Selection
| Algorithm | Speed | Ratio | Use Case | |-----------|-------|-------|----------| | LZ4 | Fastest | ~2.5:1 | Hot archives, real-time | | Zstd | Fast | ~4:1 | Cold archives, storage | | Zlib | Moderate | ~3:1 | Compatibility |
Usage
%% Compress with LZ4 (fastest)
{ok, Compressed} = esdb_archive_nif:compress(Data, lz4).
%% Compress with Zstd level 3 (good balance)
{ok, Compressed} = esdb_archive_nif:compress(Data, zstd, 3).
%% Decompress
{ok, Original} = esdb_archive_nif:decompress(Compressed, lz4).
%% Check which mode is active
nif = esdb_archive_nif:implementation(). %% Enterprise
erlang = esdb_archive_nif:implementation(). %% Community
Summary
Functions
Compress data with specified algorithm using default level.
Compress data with specified algorithm and compression level.
Compress data using LZ4 (fastest).
Compress data using Zlib with default level.
Compress data using Zlib with specified level (0-9).
Compress data using Zstd with default level.
Compress data using Zstd with specified level (1-22).
Get compression statistics for data with algorithm.
Get compression statistics with specified level.
Decompress data with specified algorithm.
Decompress LZ4-compressed data.
Decompress Zlib-compressed data.
Decompress Zstd-compressed data.
Get the current implementation mode.
Check if the NIF is loaded (Enterprise mode).
Functions
-spec compress(Data :: binary(), Algorithm :: lz4 | zstd | zlib) -> {ok, binary()} | {error, term()}.
Compress data with specified algorithm using default level.
-spec compress(Data :: binary(), Algorithm :: lz4 | zstd | zlib, Level :: integer()) -> {ok, binary()} | {error, term()}.
Compress data with specified algorithm and compression level.
Compress data using LZ4 (fastest).
Compress data using Zlib with default level.
Compress data using Zlib with specified level (0-9).
Compress data using Zstd with default level.
Compress data using Zstd with specified level (1-22).
-spec compression_stats(Data :: binary(), Algorithm :: lz4 | zstd | zlib) -> {ok, #{original_size := integer(), compressed_size := integer(), ratio := float()}} | {error, term()}.
Get compression statistics for data with algorithm.
-spec compression_stats(Data :: binary(), Algorithm :: lz4 | zstd | zlib, Level :: integer()) -> {ok, #{original_size := integer(), compressed_size := integer(), ratio := float()}} | {error, term()}.
Get compression statistics with specified level.
-spec decompress(Data :: binary(), Algorithm :: lz4 | zstd | zlib) -> {ok, binary()} | {error, term()}.
Decompress data with specified algorithm.
Decompress LZ4-compressed data.
Decompress Zlib-compressed data.
Decompress Zstd-compressed data.
-spec implementation() -> nif | erlang.
Get the current implementation mode.
-spec is_nif_loaded() -> boolean().
Check if the NIF is loaded (Enterprise mode).