use crate::result::aws::AWSError::UnrecognizedChunkFormat;
use crate::result::Error::AWS;
use crate::volume;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Chunk<'a> {
Start(volume::File),
IntermediateOrEnd(volume::Record<'a>),
}
impl Chunk<'_> {
pub fn new(data: Vec<u8>) -> crate::result::Result<Self> {
if data[0..3].as_ref() == b"AR2" {
let file = volume::File::new(data);
return Ok(Self::Start(file));
}
if data[4..6].as_ref() == b"BZ" {
let record = volume::Record::new(data);
return Ok(Self::IntermediateOrEnd(record));
}
Err(AWS(UnrecognizedChunkFormat))
}
pub fn data(&self) -> &[u8] {
match self {
Self::Start(file) => file.data(),
Self::IntermediateOrEnd(record) => record.data(),
}
}
}