use crate::sfa::{
toc::{Toc, reader::TocReader},
trailer::reader::TrailerReader,
};
use std::io::{BufReader, Read, Seek};
pub struct Reader {
toc: Toc,
}
impl Reader {
pub fn new(path: impl AsRef<std::path::Path>) -> crate::sfa::Result<Self> {
let file = std::fs::File::open(path)?;
let mut file = BufReader::with_capacity(4_096, file);
let trailer = TrailerReader::from_reader(&mut file)?;
let toc = TocReader::from_reader(
&mut file,
trailer.toc_pos,
trailer.toc_len,
trailer.toc_checksum,
)?;
Ok(Self { toc })
}
pub fn from_reader<R: Read + Seek>(reader: &mut R) -> crate::sfa::Result<Self> {
let trailer = TrailerReader::from_reader(reader)?;
let toc = TocReader::from_reader(
reader,
trailer.toc_pos,
trailer.toc_len,
trailer.toc_checksum,
)?;
Ok(Self { toc })
}
#[must_use]
pub fn toc(&self) -> &Toc {
&self.toc
}
}