Skip to main content

compress_to_buffer

Function compress_to_buffer 

Source
pub fn compress_to_buffer(
    source: &[u8],
    destination: &mut [u8],
    level: i32,
) -> Result<usize>
Expand description

Compresses a single block of data to the given destination buffer.

Returns the number of bytes written, or an error if something happened (for instance if the destination buffer was too small).

crate::compress_bound() says how large the destination might need to be. Passing a Vec instead of a slice works too, and then it is the Vec’s capacity that bounds the output - so reserve what you need rather than resize, since the bytes do not have to be initialized.

A level of 0 uses zstd’s default (currently 3).