mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 10:54:38 +00:00
gzip support
This commit is contained in:
parent
f2f7d93fe2
commit
600bbd21a1
1 changed files with 27 additions and 22 deletions
49
src/entry.rs
49
src/entry.rs
|
@ -90,33 +90,38 @@ impl Entry {
|
|||
data.truncate(self.compressed as usize);
|
||||
}
|
||||
use io::Write;
|
||||
match self.compression {
|
||||
Compression::None => buf.write_all(&data)?,
|
||||
Compression::Zlib => match &self.blocks {
|
||||
Some(blocks) => {
|
||||
for block in blocks {
|
||||
macro_rules! decompress {
|
||||
($decompressor: ty) => {
|
||||
match &self.blocks {
|
||||
Some(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(
|
||||
&mut flate2::read::ZlibDecoder::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 flate2::read::ZlibDecoder::new(data.as_slice()),
|
||||
&mut buf,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
None => {
|
||||
io::copy(
|
||||
&mut flate2::read::ZlibDecoder::new(data.as_slice()),
|
||||
&mut buf,
|
||||
)?;
|
||||
}
|
||||
},
|
||||
Compression::Gzip => todo!(),
|
||||
};
|
||||
}
|
||||
match self.compression {
|
||||
Compression::None => buf.write_all(&data)?,
|
||||
Compression::Zlib => decompress!(flate2::read::ZlibDecoder<&[u8]>),
|
||||
Compression::Gzip => decompress!(flate2::read::GzDecoder<&[u8]>),
|
||||
Compression::Oodle => todo!(),
|
||||
}
|
||||
buf.flush()?;
|
||||
|
|
Loading…
Reference in a new issue