pacenotes_installer\zip/
archive.rs1pub struct Archive<'a> {
5 zip: &'a [u8],
6 entries: std::collections::BTreeMap<String, super::central_directory::Entry>,
8}
9
10impl<'a> Archive<'a> {
11 pub fn open(zip: &'a [u8]) -> Result<Archive<'a>, super::ZipError> {
12 let mut entries = std::collections::BTreeMap::new();
13 for entry in super::central_directory::read(zip)? {
14 if !entry.is_dir {
16 entries.entry(entry.path.to_lowercase()).or_insert(entry);
17 }
18 }
19 Ok(Archive { zip, entries })
20 }
21
22 pub fn read(&self, path: &str) -> Result<Vec<u8>, super::ZipError> {
24 let entry = self
25 .entries
26 .get(&path.to_lowercase())
27 .ok_or_else(|| super::ZipError::new(format!("{path} is not in this package")))?;
28 super::entry_data::read(self.zip, entry)
29 }
30}