working decompression? (iter time)

This commit is contained in:
spuds 2023-01-13 18:12:47 +00:00
parent c0107af12f
commit cf98aa3a60
2 changed files with 27 additions and 8 deletions

View file

@ -12,6 +12,7 @@ edition = "2021"
byteorder = "*" byteorder = "*"
strum = { version = "*", features = ["derive"] } strum = { version = "*", features = ["derive"] }
aes = "*" aes = "*"
flate2 = "*"
hashbrown = "*" hashbrown = "*"
thiserror = "*" thiserror = "*"

View file

@ -4,16 +4,15 @@ use std::io;
#[derive(Debug)] #[derive(Debug)]
pub struct Block { pub struct Block {
pub offset: u64, pub start: u64,
/// size of the compressed block pub end: u64,
pub size: u64,
} }
impl Block { impl Block {
pub fn new<R: io::Read>(reader: &mut R) -> Result<Self, super::Error> { pub fn new<R: io::Read>(reader: &mut R) -> Result<Self, super::Error> {
Ok(Self { Ok(Self {
offset: reader.read_u64::<LE>()?, start: reader.read_u64::<LE>()?,
size: reader.read_u64::<LE>()?, end: reader.read_u64::<LE>()?,
}) })
} }
} }
@ -26,7 +25,7 @@ pub struct Entry {
pub compression: Compression, pub compression: Compression,
pub timestamp: Option<u64>, pub timestamp: Option<u64>,
pub hash: [u8; 20], pub hash: [u8; 20],
pub compression_blocks: Option<Vec<Block>>, pub blocks: Option<Vec<Block>>,
pub encrypted: bool, pub encrypted: bool,
pub block_uncompressed: Option<u32>, pub block_uncompressed: Option<u32>,
} }
@ -51,7 +50,7 @@ impl Entry {
false => None, false => None,
}, },
hash: reader.read_guid()?, hash: reader.read_guid()?,
compression_blocks: match version >= Version::CompressionEncryption blocks: match version >= Version::CompressionEncryption
&& compression != Compression::None && compression != Compression::None
{ {
true => Some(reader.read_array(Block::new)?), true => Some(reader.read_array(Block::new)?),
@ -90,7 +89,26 @@ impl Entry {
use io::Write; use io::Write;
match self.compression { match self.compression {
Compression::None => buf.write_all(&data)?, Compression::None => buf.write_all(&data)?,
Compression::Zlib => todo!(), Compression::Zlib => {
let mut decoder = flate2::write::ZlibDecoder::new(buf);
match &self.blocks {
Some(blocks) => {
for block in blocks {
decoder.write(
&data[match version >= Version::RelativeChunkOffsets {
true => {
(block.start - self.offset) as usize
..(block.end - self.offset) as usize
}
false => block.start as usize..block.end as usize,
}],
)?;
}
}
None => decoder.write_all(&data)?,
}
buf = decoder.finish()?;
}
Compression::Gzip => todo!(), Compression::Gzip => todo!(),
Compression::Oodle => todo!(), Compression::Oodle => todo!(),
} }