Expand description
Pure Rust LZF compression and decompression.
§Overview
This crate provides:
- Raw LZF token encode/decode (
compress/decompress). lzfblock framing support (ZV\0/ZV\1) viaencode_blocks/decode_blocks.- Streaming adapters (
LzfReader,LzfWriter) for framed streams. no_std-compatible I/O traits (LzfRead,LzfWrite).
Raw token compatibility matches liblzf (lzf_compress, lzf_compress_best,
and lzf_decompress behavior for valid inputs).
§Features
std(default): integrates withstd::io::{Read, Write}.encoder(default): enables compression APIs andLzfWriter.
§no_std
Disable default features to use in no_std + alloc environments:
[dependencies]
lzf-rust = { version = "0.1", default-features = false, features = ["encoder"] }In this mode, use crate-level LzfRead/LzfWrite traits.
§Examples
Raw token roundtrip:
use lzf_rust::{compress, decompress, max_compressed_size};
let input = b"hello hello hello hello";
let mut compressed = vec![0u8; max_compressed_size(input.len())];
let n = compress(input, &mut compressed).unwrap();
compressed.truncate(n);
let mut out = vec![0u8; input.len()];
let m = decompress(&compressed, &mut out).unwrap();
assert_eq!(m, input.len());
assert_eq!(&out, input);Framed block roundtrip:
use lzf_rust::{decode_blocks, encode_blocks};
let input = b"framed lzf data";
let framed = encode_blocks(input, 32 * 1024).unwrap();
let decoded = decode_blocks(&framed).unwrap();
assert_eq!(decoded, input);§Safety
This crate forbids unsafe code.
§License
This repository uses file-level licensing:
src/raw/encoder.rs:BSD-2-Clause(derived from liblzf encoder logic).- Remaining from-scratch Rust sources:
ISC.
Structs§
- Auto
Finisher - Wrapper that attempts to finish the wrapped writer on drop.
- LzfReader
- Framed LZF stream reader.
Reader that decodes framed LZF (
ZVblock stream). - LzfWriter
encoder - Framed LZF stream writer.
Writer that encodes framed LZF (
ZVblock stream).
Enums§
- Compression
Mode encoder - Raw LZF encoder APIs. Encoder mode for raw LZF compression.
- Error
- Crate error and result types. Error type for LZF encode/decode operations.
Constants§
- MAX_
LITERAL_ LEN - Maximum literal run size in the LZF format.
- MAX_
MATCH_ LEN - Maximum match length in the LZF format.
- MAX_
OFFSET - Maximum backwards offset in the LZF format.
Traits§
- LzfRead
- Alias for
Readto mirror naming used by related compression crates.no_std-compatible read trait used by streaming interfaces. - LzfWrite
- Alias for
Readto mirror naming used by related compression crates.no_std-compatible write trait used by streaming interfaces. - Read
no_std-compatible read/write traits used by streaming APIs.no_std-compatible read trait used by streaming interfaces.- Write
no_std-compatible read/write traits used by streaming APIs.no_std-compatible write trait used by streaming interfaces.
Functions§
- compress
encoder - Raw LZF encoder APIs.
Compresses
inputintooutputusing raw LZF format. - compress_
best encoder - Raw LZF encoder APIs.
Compresses
inputintooutputusing liblzf best-compression mode. - compress_
with_ mode encoder - Raw LZF encoder APIs.
Compresses
inputintooutputusing the given encoder mode. - decode_
blocks - Decodes
lzfframed block streams (ZV\0/ZV\1). Decodes data encoded withencode_blocksor thelzfutility stream format. - decompress
- Raw LZF decoder APIs.
Decompresses raw LZF
inputintooutput. - decompress_
into_ vec - Raw LZF decoder APIs.
Decompresses raw LZF
inputinto a freshVec<u8>ofoutput_lenbytes. - encode_
blocks encoder - Encodes bytes into
lzfframed block streams (ZV\0/ZV\1). Encodes input intolzfblock stream format (ZV\0/ZV\1blocks). - encode_
blocks_ with_ mode encoder - Encodes bytes into framed block streams with an explicit compression mode.
Encodes input into
lzfblock stream format (ZV\0/ZV\1blocks), selecting the raw compressor mode. - max_
compressed_ size - Computes a guaranteed upper bound for compressed output size.
Type Aliases§
- Result
- Crate error and result types. Result type used by this crate.