Module: compress.lz4
Source: ./compress/lz4.reef
Overview
compress/lz4 - LZ4 fast compression using FFI
This module provides LZ4 compression/decompression using the system's liblz4 library via FFI. LZ4 is designed for very fast compression and decompression speeds.
IMPORTANT: This module requires the LZ4 library (-llz4) to be linked. Install: apt install liblz4-dev (Debian/Ubuntu)
Usage: import compress.lz4 unsafe let src: [byte] = lz4_alloc_buffer(100) // Fill src with data let dest: [byte] = lz4_alloc_buffer(lz4_compress_bound(100)) let compressed_len = lz4_compress(src, 100, dest, dest_size) end unsafe
Functions
fn LZ4_compressBound(inputSize: int): int
LZ4 FFI functions
fn LZ4_compress_default(src: pointer, dst: pointer, srcSize: int, dstCapacity: int): int
fn LZ4_compress_fast(src: pointer, dst: pointer, srcSize: int, dstCapacity: int, acceleration: int): int
fn LZ4_compress_HC(src: pointer, dst: pointer, srcSize: int, dstCapacity: int, compressionLevel: int): int
fn LZ4_decompress_safe(src: pointer, dst: pointer, compressedSize: int, dstCapacity: int): int
fn LZ4_HC_MIN(): int
fn LZ4_HC_DEFAULT(): int
fn LZ4_HC_MAX(): int
fn lz4_alloc_buffer(size: int): [uint8]
Allocate a byte buffer for use with LZ4 functions
fn lz4_compress_bound(src_len: int): int
Returns the maximum compressed size for given input size
fn lz4_wrap_compress(n: int): result.Result[int, error.Error]
All three compressors share one failure convention, so they share one wrapper. LZ4 returns 0 -- and ONLY 0 -- on failure, which per the LZ4 contract means dest was not large enough; a successful compression is always a positive byte count.
fn lz4_compress(src: [uint8], src_len: int, dest: [uint8], dest_len: int): result.Result[int, error.Error]
Compress data using default settings
fn lz4_compress_fast(src: [uint8], src_len: int, dest: [uint8], dest_len: int, accel: int): result.Result[int, error.Error]
Compress data with speed acceleration. acceleration: 1 = default, higher values = faster but worse ratio
fn lz4_compress_hc(src: [uint8], src_len: int, dest: [uint8], dest_len: int, level: int): result.Result[int, error.Error]
Compress data using high compression mode (slower, better ratio). level: 3 (min) to 12 (max), 9 is default
fn lz4_decompress(src: [uint8], src_len: int, dest: [uint8], dest_len: int): result.Result[int, error.Error]
Decompress data dest_len: maximum expected decompressed size (must be exact or larger) Returns decompressed size, or negative value on error
Generated by reefc doc