diff options
| author | Valentin Popov <valentin@popov.link> | 2026-02-10 11:38:58 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-02-10 11:38:58 +0300 |
| commit | 842f4a85693b418af81560738aa3136ac500d9b1 (patch) | |
| tree | d18cf54120294a312bf90d2a5282e3d640c43c57 /crates/rsli/src/compress/deflate.rs | |
| parent | ce6e30f7272fd0c064ef52ac85cad1c0f05fd323 (diff) | |
| download | fparkan-842f4a85693b418af81560738aa3136ac500d9b1.tar.xz fparkan-842f4a85693b418af81560738aa3136ac500d9b1.zip | |
Implement LZSS decompression with optional XOR decryption
- Added `lzss_decompress_simple` function for LZSS decompression in `lzss.rs`.
- Introduced `XorState` struct and `xor_stream` function for XOR decryption in `xor.rs`.
- Updated `mod.rs` to include new LZSS and XOR modules.
- Refactored `parse_library` function in `parse.rs` to utilize the new XOR decryption functionality.
- Cleaned up and organized code in `lib.rs` by removing redundant functions and structures.
- Added tests for new functionality in `tests.rs`.
Diffstat (limited to 'crates/rsli/src/compress/deflate.rs')
| -rw-r--r-- | crates/rsli/src/compress/deflate.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/rsli/src/compress/deflate.rs b/crates/rsli/src/compress/deflate.rs new file mode 100644 index 0000000..154e0e3 --- /dev/null +++ b/crates/rsli/src/compress/deflate.rs @@ -0,0 +1,19 @@ +use crate::error::Error; +use crate::Result; +use flate2::read::{DeflateDecoder, ZlibDecoder}; +use std::io::Read; + +/// Decode Deflate or Zlib compressed data +pub fn decode_deflate(packed: &[u8]) -> Result<Vec<u8>> { + let mut out = Vec::new(); + let mut decoder = DeflateDecoder::new(packed); + if decoder.read_to_end(&mut out).is_ok() { + return Ok(out); + } + + out.clear(); + let mut zlib = ZlibDecoder::new(packed); + zlib.read_to_end(&mut out) + .map_err(|_| Error::DecompressionFailed("deflate"))?; + Ok(out) +} |
