[][src]Function lzzzz::lz4_hc::compress

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

Performs LZ4_HC block compression.

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

Returns the number of bytes written into the destination buffer.

Example

use lzzzz::{lz4, lz4_hc};

let data = b"The quick brown fox jumps over the lazy dog.";
let mut buf = [0u8; 256];

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

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