mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 19:04:07 +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);
|
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()?;
|
||||||
|
|
Loading…
Reference in a new issue