#[export_name = "compress"]
pub unsafe extern "C-unwind" fn compress(
dest: *mut Bytef,
destLen: *mut c_ulong,
source: *const Bytef,
sourceLen: c_ulong,
) -> c_intExpand description
Compresses source into dest, and writes the final deflated size into destLen.
sourceLen is the byte length of the source buffer.
Upon entry, destLen is the total size of the destination buffer,
which must be at least the value returned by compressBound(sourceLen).
Upon exit, destLen is the actual size of the compressed data.
A call to compress is equivalent to compress2 with a level parameter of Z_DEFAULT_COMPRESSION.
§Returns
Z_OKif successZ_MEM_ERRORif there was not enough memoryZ_BUF_ERRORif there was not enough room in the output buffer
§Safety
The caller must guarantee that
- The
destLenpointer satisfies the requirements ofcore::ptr::read - Either
destisNULLdestand*destLensatisfy the requirements ofcore::slice::from_raw_parts_mut::<MaybeUninit<u8>>
- Either
sourceisNULLsourceandsourceLensatisfy the requirements ofcore::slice::from_raw_parts
§Example
use libz_rs_sys::{Z_OK, compress};
let source = b"Ferris";
let mut dest = vec![0u8; 100];
let mut dest_len = dest.len() as _;
let err = unsafe {
compress(
dest.as_mut_ptr(),
&mut dest_len,
source.as_ptr(),
source.len() as _,
)
};
assert_eq!(err, Z_OK);
assert_eq!(dest_len, 14);
dest.truncate(dest_len as usize);
assert_eq!(dest, [120, 156, 115, 75, 45, 42, 202, 44, 6, 0, 8, 6, 2, 108]);