#[unsafe(export_name = "uncompress")]pub unsafe extern "C-unwind" fn uncompress(
dest: *mut u8,
destLen: *mut u64,
source: *const u8,
sourceLen: u64,
) -> i32Expand 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_OKif successZ_MEM_ERRORif there was not enough memoryZ_BUF_ERRORif there was not enough room in the output bufferZ_DATA_ERRORif 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
destLenisNULLdestLensatisfies the requirements of&mut *destLen
- Either
destisNULLdestand*destLensatisfy the requirements ofcore::slice::from_raw_parts_mut::<MaybeUninit<u8>>
- Either
sourceisNULLsourceandsourceLensatisfy 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");