pub struct BlockHeader {
pub header_size: u16,
pub flags: u32,
pub compression: [u8; 4],
pub allocated_size: u64,
pub used_size: u64,
pub data_size: u64,
pub checksum: [u8; 16],
}Expand description
A decoded block header.
Fields§
§header_size: u16The header size as recorded in the file, excluding the magic and this field. Preserved so a re-emitted block keeps any padding it had.
flags: u32Flag bits; see FLAG_STREAMED.
compression: [u8; 4]The compression name, \0-padded to four bytes in the file.
allocated_size: u64Space reserved for the block’s data, excluding the header.
used_size: u64Bytes actually used on disk, excluding the header.
data_size: u64Size of the data once decoded. Equal to used_size when uncompressed.
checksum: [u8; 16]MD5 of the used data. All-zero means “do not verify”.
Implementations§
Source§impl BlockHeader
impl BlockHeader
Sourcepub fn parse(buf: &[u8]) -> Result<(Self, usize)>
pub fn parse(buf: &[u8]) -> Result<(Self, usize)>
Decode a header from a buffer positioned at the block magic.
Returns the header and the number of bytes it occupied, so the caller can find the data that follows.
Sourcepub fn write(&self, out: &mut Vec<u8>)
pub fn write(&self, out: &mut Vec<u8>)
Encode the header, including magic, into out.
Any header_size beyond the fields is written as zero padding, so a
block that was read with an enlarged header re-emits at the same size.
Sourcepub fn on_disk_size(&self) -> usize
pub fn on_disk_size(&self) -> usize
The number of bytes this header occupies in the file.
Sourcepub fn is_streamed(&self) -> bool
pub fn is_streamed(&self) -> bool
Whether the streamed flag is set.
Sourcepub fn compression_name(&self) -> &str
pub fn compression_name(&self) -> &str
The compression name with its \0 padding removed.
An empty name means the block is uncompressed.
Sourcepub fn set_compression(&mut self, name: &str) -> Result<()>
pub fn set_compression(&mut self, name: &str) -> Result<()>
Set the compression name, which must fit in four bytes.
Sourcepub fn has_checksum(&self) -> bool
pub fn has_checksum(&self) -> bool
Whether a checksum is recorded. All-zero means “do not verify”.
Trait Implementations§
Source§impl Clone for BlockHeader
impl Clone for BlockHeader
Source§fn clone(&self) -> BlockHeader
fn clone(&self) -> BlockHeader
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more