1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-25 13:57:45 +00:00
physis/src/compression.rs
Joshua Goins d58a216462 Shrink the dependency and feature complexity, auto-cleanup and more
We had a few odd dependencies that caused nothing but pain in dependent projects
like libphysis. One of these was libunshield (a C library) that our game_install
feature used, but to be honest this was the wrong library to put this code. It
was really only ever used by Astra, and should live there instead - there's no
reason to have it shared between applications (and it's small enough to be
copied if *you* need it.) Also that also killed the system-deps dependency which
had a significant impact on our build time.

Another dependency was replaced: libz-sys. This is replaced by the pure Rust
libz-rs (through libz-rs-sys) which should simplify deploying physis without
having to worry about manually linking libz or other nonsense. Some leftover
copied code from flate2 can also be removed.

I also removed the visual_data feature as Astra ended up using it anyway, and
the distinction doesn't make much sense now. It was previously to gate some
dependencies needed for visual data extraction, but the bitflags and half crates
are small. I can look into splitting the crate up into more features if needed
later.

A dependency that was erroneously included in the refactoring was quote, which
has been removed. Also ran cargo fmt, clippy too.
2025-03-11 16:29:24 -04:00

50 lines
1.3 KiB
Rust
Executable file

// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
use std::ptr::null_mut;
use libz_rs_sys::*;
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
opaque: null_mut(),
data_type: 0,
adler: 0,
reserved: 0,
};
let ret = inflateInit2_(
&mut strm,
-15,
zlibVersion(),
core::mem::size_of::<z_stream>() as i32,
);
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
}
}