Skip to main content

Crate lzf_rust

Crate lzf_rust 

Source
Expand description

Pure Rust LZF compression and decompression.

§Overview

This crate provides:

  • Raw LZF token encode/decode (compress/decompress).
  • lzf block framing support (ZV\0/ZV\1) via encode_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 with std::io::{Read, Write}.
  • encoder (default): enables compression APIs and LzfWriter.

§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§

AutoFinisher
Wrapper that attempts to finish the wrapped writer on drop.
LzfReader
Framed LZF stream reader. Reader that decodes framed LZF (ZV block stream).
LzfWriterencoder
Framed LZF stream writer. Writer that encodes framed LZF (ZV block stream).

Enums§

CompressionModeencoder
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 Read to mirror naming used by related compression crates. no_std-compatible read trait used by streaming interfaces.
LzfWrite
Alias for Read to 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§

compressencoder
Raw LZF encoder APIs. Compresses input into output using raw LZF format.
compress_bestencoder
Raw LZF encoder APIs. Compresses input into output using liblzf best-compression mode.
compress_with_modeencoder
Raw LZF encoder APIs. Compresses input into output using the given encoder mode.
decode_blocks
Decodes lzf framed block streams (ZV\0/ZV\1). Decodes data encoded with encode_blocks or the lzf utility stream format.
decompress
Raw LZF decoder APIs. Decompresses raw LZF input into output.
decompress_into_vec
Raw LZF decoder APIs. Decompresses raw LZF input into a fresh Vec<u8> of output_len bytes.
encode_blocksencoder
Encodes bytes into lzf framed block streams (ZV\0/ZV\1). Encodes input into lzf block stream format (ZV\0/ZV\1 blocks).
encode_blocks_with_modeencoder
Encodes bytes into framed block streams with an explicit compression mode. Encodes input into lzf block stream format (ZV\0/ZV\1 blocks), 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.