2023-01-03 14:20:35 +00:00
|
|
|
use byteorder::{ReadBytesExt, LE};
|
|
|
|
|
|
|
|
use super::{Compression, ReadExt, Version};
|
|
|
|
|
2023-01-06 19:54:48 +00:00
|
|
|
#[derive(Debug)]
|
2023-01-03 14:20:35 +00:00
|
|
|
pub struct Entry {
|
|
|
|
pub offset: u64,
|
|
|
|
pub compressed: u64,
|
|
|
|
pub uncompressed: u64,
|
|
|
|
pub compression_method: Compression,
|
|
|
|
pub timestamp: Option<u64>,
|
|
|
|
pub hash: [u8; 20],
|
|
|
|
pub compression_blocks: Option<Vec<Block>>,
|
2023-01-10 22:29:20 +00:00
|
|
|
pub encrypted: bool,
|
|
|
|
pub block_uncompressed: Option<u32>,
|
2023-01-03 14:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Entry {
|
|
|
|
pub fn new<R: std::io::Read>(
|
|
|
|
reader: &mut R,
|
2023-01-07 21:10:11 +00:00
|
|
|
version: super::Version,
|
2023-01-03 14:20:35 +00:00
|
|
|
) -> Result<Self, super::Error> {
|
|
|
|
let offset = reader.read_u64::<LE>()?;
|
|
|
|
let compressed = reader.read_u64::<LE>()?;
|
|
|
|
let uncompressed = reader.read_u64::<LE>()?;
|
|
|
|
let compression_method = match reader.read_u32::<LE>()? {
|
2023-01-10 22:29:20 +00:00
|
|
|
0x01 | 0x10 | 0x20 => Compression::Zlib,
|
2023-01-03 14:20:35 +00:00
|
|
|
_ => Compression::None,
|
|
|
|
};
|
|
|
|
Ok(Self {
|
|
|
|
offset,
|
|
|
|
compressed,
|
|
|
|
uncompressed,
|
|
|
|
compression_method,
|
2023-01-10 22:29:20 +00:00
|
|
|
timestamp: match version == Version::Initial {
|
|
|
|
true => Some(reader.read_u64::<LE>()?),
|
|
|
|
false => None,
|
|
|
|
},
|
2023-01-03 14:20:35 +00:00
|
|
|
hash: reader.read_guid()?,
|
2023-01-10 22:29:20 +00:00
|
|
|
compression_blocks: match version >= Version::CompressionEncryption
|
|
|
|
&& compression_method != Compression::None
|
|
|
|
{
|
|
|
|
true => Some(reader.read_array(Block::new)?),
|
|
|
|
false => None,
|
|
|
|
},
|
|
|
|
encrypted: version >= Version::CompressionEncryption && reader.read_bool()?,
|
|
|
|
block_uncompressed: match version >= Version::CompressionEncryption {
|
|
|
|
true => Some(reader.read_u32::<LE>()?),
|
|
|
|
false => None,
|
|
|
|
},
|
2023-01-03 14:20:35 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-06 19:54:48 +00:00
|
|
|
#[derive(Debug)]
|
2023-01-03 14:20:35 +00:00
|
|
|
pub struct Block {
|
|
|
|
/// start offset relative to the start of the entry header
|
|
|
|
pub offset: u64,
|
|
|
|
/// size of the compressed block
|
|
|
|
pub size: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Block {
|
|
|
|
pub fn new<R: std::io::Read>(reader: &mut R) -> Result<Self, super::Error> {
|
|
|
|
Ok(Self {
|
|
|
|
offset: reader.read_u64::<LE>()?,
|
|
|
|
size: reader.read_u64::<LE>()?,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|