gzip support

This commit is contained in:
spuds 2023-01-14 15:17:24 +00:00
parent f2f7d93fe2
commit 600bbd21a1

View file

@ -90,33 +90,38 @@ impl Entry {
data.truncate(self.compressed as usize); data.truncate(self.compressed as usize);
} }
use io::Write; use io::Write;
match self.compression { macro_rules! decompress {
Compression::None => buf.write_all(&data)?, ($decompressor: ty) => {
Compression::Zlib => match &self.blocks { match &self.blocks {
Some(blocks) => { Some(blocks) => {
for block in blocks { for block in blocks {
io::copy(
&mut <$decompressor>::new(
&data[match version >= Version::RelativeChunkOffsets {
true => block.start as usize..block.end as usize,
false => {
(block.start - data_offset) as usize
..(block.end - data_offset) as usize
}
}],
),
&mut buf,
)?;
}
}
None => {
io::copy( io::copy(
&mut flate2::read::ZlibDecoder::new( &mut flate2::read::ZlibDecoder::new(data.as_slice()),
&data[match version >= Version::RelativeChunkOffsets {
true => block.start as usize..block.end as usize,
false => {
(block.start - data_offset) as usize
..(block.end - data_offset) as usize
}
}],
),
&mut buf, &mut buf,
)?; )?;
} }
} }
None => { };
io::copy( }
&mut flate2::read::ZlibDecoder::new(data.as_slice()), match self.compression {
&mut buf, Compression::None => buf.write_all(&data)?,
)?; Compression::Zlib => decompress!(flate2::read::ZlibDecoder<&[u8]>),
} Compression::Gzip => decompress!(flate2::read::GzDecoder<&[u8]>),
},
Compression::Gzip => todo!(),
Compression::Oodle => todo!(), Compression::Oodle => todo!(),
} }
buf.flush()?; buf.flush()?;