#[export_name = "uncompress"]
pub unsafe extern "C-unwind" fn uncompress(
dest: *mut u8,
destLen: *mut c_ulong,
source: *const u8,
sourceLen: c_ulong,
) -> c_int
Expand description
Inflates source
into dest
, and writes the final inflated size into destLen
.
Upon entry, destLen
is the total size of the destination buffer, which must be large enough to hold the entire
uncompressed data. (The size of the uncompressed data must have been saved previously by the compressor and
transmitted to the decompressor by some mechanism outside the scope of this compression library.)
Upon exit, destLen
is the actual size of the uncompressed data.
§Returns
Z_OK
if successZ_MEM_ERROR
if there was not enough memoryZ_BUF_ERROR
if there was not enough room in the output bufferZ_DATA_ERROR
if the input data was corrupted or incomplete
In the case where there is not enough room, uncompress
will fill the output buffer with the uncompressed data up to that point.
§Safety
The caller must guarantee that
- Either
destLen
isNULL
destLen
satisfies the requirements of&mut *destLen
- 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::<u8>
§Example
use libz_rs_sys::{Z_OK, uncompress};
let source = [120, 156, 115, 75, 45, 42, 202, 44, 6, 0, 8, 6, 2, 108];
let mut dest = vec![0u8; 100];
let mut dest_len = dest.len() as _;
let err = unsafe {
uncompress(
dest.as_mut_ptr(),
&mut dest_len,
source.as_ptr(),
source.len() as _,
)
};
assert_eq!(err, Z_OK);
assert_eq!(dest_len, 6);
dest.truncate(dest_len as usize);
assert_eq!(dest, b"Ferris");