diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 756559f7..1a13b4cf 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -4,6 +4,7 @@ use std::collections::HashMap; use std::fs::File as FSFile; use std::ops::Deref; use std::io::Write; +use std::io::Read; pub mod path; pub mod file; @@ -41,6 +42,26 @@ impl Store { res } + pub fn load_in_cache(&self, m: &Module, parser: &Parser, id: FileID) + -> Option>> + where HP: FileHeaderParser + { + let idstr : String = id.clone().into(); + let path = format!("{}/{}-{}.imag", self.storepath, m.name(), idstr); + let mut string = String::new(); + + FSFile::open(&path).map(|mut file| { + file.read_to_string(&mut string) + .map_err(|e| error!("Failed reading file: '{}'", path)); + }); + + parser.read(string).map(|(header, data)| { + self.new_file_from_parser_result(m, id.clone(), header, data); + }); + + self.load(&id) + } + pub fn new_file(&self, module: &Module) -> FileID {