#[export_name = "compress"]
pub unsafe extern "C-unwind" fn compress(
dest: *mut Bytef,
destLen: *mut c_ulong,
source: *const Bytef,
sourceLen: c_ulong,
) -> c_int
Expand 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_OK
if successZ_MEM_ERROR
if there was not enough memoryZ_BUF_ERROR
if there was not enough room in the output buffer
§Safety
The caller must guarantee that
- The
destLen
pointer satisfies the requirements ofcore::ptr::read
- Either
dest
isNULL
dest
and*destLen
satisfy the requirements ofcore::slice::from_raw_parts_mut::<MaybeUninit<u8>>
- Either
source
isNULL
source
andsourceLen
satisfy 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]);