1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-25 13:57:45 +00:00
physis/src/compression.rs

51 lines
1.3 KiB
Rust
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
2022-08-16 11:52:07 -04:00
use std::ptr::null_mut;
2022-07-19 19:29:41 -04:00
use libz_rs_sys::*;
2022-07-19 19:29:41 -04:00
pub fn no_header_decompress(in_data: &mut [u8], out_data: &mut [u8]) -> bool {
unsafe {
let mut strm = z_stream {
next_in: null_mut(),
avail_in: in_data.len() as u32,
total_in: 0,
next_out: null_mut(),
avail_out: 0,
total_out: 0,
msg: null_mut(),
state: null_mut(),
zalloc: None, // the default alloc is fine
zfree: None, // the default free is fine
2022-07-19 19:29:41 -04:00
opaque: null_mut(),
data_type: 0,
adler: 0,
reserved: 0,
};
2022-08-16 11:52:07 -04:00
let ret = inflateInit2_(
&mut strm,
-15,
zlibVersion(),
core::mem::size_of::<z_stream>() as i32,
);
2022-07-19 19:29:41 -04:00
if ret != Z_OK {
return false;
}
strm.next_in = in_data.as_mut_ptr();
strm.avail_out = out_data.len() as u32;
strm.next_out = out_data.as_mut_ptr();
let ret = inflate(&mut strm, Z_NO_FLUSH);
if ret != Z_STREAM_END {
return false;
}
inflateEnd(&mut strm);
true
}
2022-08-16 11:52:07 -04:00
}