[][src]Function lzzzz::lz4f::compress

pub fn compress(
    src: &[u8],
    dst: &mut [u8],
    prefs: &Preferences
) -> Result<usize>

Performs LZ4F compression.

Ensure that the destination slice have enough capacity. If dst.len() is smaller than lz4f::max_compressed_size(src.len()), this function may fail.

Returns the number of bytes written into the destination buffer.

Example

Compress data with the default compression mode:

use lzzzz::lz4f;

let prefs = lz4f::Preferences::default();
let data = b"The quick brown fox jumps over the lazy dog.";
let mut buf = [0u8; 2048];

// The slice should have enough capacity.
assert!(buf.len() >= lz4f::max_compressed_size(data.len(), &prefs));

let len = lz4f::compress(data, &mut buf, &prefs)?;
let compressed = &buf[..len];