1mod reading;
2mod writing;
3mod file_wrapper;
4
5pub use reading::*;
6pub use writing::*;
7pub use file_wrapper::*;
8
9use std::path::{Path, PathBuf};
10use crate::*;
11
12pub struct LazyData {
13 pub path: PathBuf,
14 pub lazy_type: LazyType,
15 wrapper: FileWrapper,
16}
17
18impl LazyData {
19 pub fn load(path: impl AsRef<Path>) -> Result<Self, LDBError> {
20 let path = path.as_ref();
21
22 if !path.is_file() { return Err(LDBError::FileNotFound(path.to_path_buf())) };
24
25 let mut reader =
27 FileWrapper::new_reader(unwrap_result!((std::fs::File::open(path)) err => LDBError::IOError(err)));
28
29 let lazy_type =
31 LazyType::try_from(reader.read(1)?[0])?;
32
33 Ok(Self {
34 path: path.to_path_buf(),
35 lazy_type,
36 wrapper: reader,
37 })
38 }
39
40 pub fn get_path(&self) -> PathBuf {
41 self.path.clone()
42 }
43}