1pub mod section;
4
5use std::io::{self, Read, Seek, SeekFrom};
6
7use section::{Section, BWTB};
8
9
10pub struct CompiledSpace<R> {
12 pub inner: R,
13 pub bwtb: BWTB,
14}
15
16impl<R: Read + Seek> CompiledSpace<R> {
17
18 pub fn new(mut inner: R) -> io::Result<Self> {
22
23 let bwtb = BWTB::decode(&mut inner)?;
24
25 Ok(CompiledSpace {
26 inner,
27 bwtb,
28 })
29
30 }
31
32 pub fn decode_section<S: Section>(&mut self) -> Option<S> {
34 let meta = self.bwtb.get_section_meta(S::ID)?;
35 self.inner.seek(SeekFrom::Start(meta.off as u64)).ok()?;
36 Some(S::decode(&mut self.inner).unwrap())
37 }
38
39}