Crate lz4_java_wrc

source ·
Expand description

A Rust implementation of the LZ4BlockOutputStream format from lz4-java.

Beware: this format is not compatible with the standard LZ4 Block format. You should not use it if you unless you have to work with some historical data compressed using the Java code.

§Example

use lz4_java_wrc::{Lz4BlockInput, Lz4BlockOutput};
use std::io::{Read, Result, Write};

fn compress(d: &str) -> Result<Vec<u8>> {
    let mut compressed = Vec::new();
    Lz4BlockOutput::new(&mut compressed).write_all(d.as_bytes())?;
    Ok(compressed)
}
fn decompress(r: &[u8]) -> Result<String> {
    let mut decompressed = String::new();
    Lz4BlockInput::new(r).read_to_string(&mut decompressed)?;
    Ok(decompressed)
}

fn main() -> Result<()> {
    // compress the string
    let compressed = compress("Hello World!")?;

    // decompress back into the original value
    let decompressed = decompress(compressed.as_slice())?;
    println!("{}", decompressed);
    Ok(())
}

§Feature Flags

  • use_lz4_flex: use lz4_flex as lz4 compression library (enabled by default)
  • use_lz4-sys: use lz4-sys as lz4 compression library (disabled by default)

When compiling with one of the lz4 compression library, it is used by default. When compiling with both of them, one can choose with the Context enum.

Structs§

Enums§

  • Use a given context to switch between LZ4 libraries.

Traits§

  • Used to provide implementation for the LZ4 compression/decompression methods

Type Aliases§