mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:42:27 +00:00
Merge pull request #1690 from storytold/codex/format-owned-archive
Keep format container bytes in the ZIP archive
This commit is contained in:
1 file changed
+5
-13
@@ -177,13 +177,10 @@ impl Writer {
|
||||
}
|
||||
}
|
||||
|
||||
/// A container being read. Opening reads all bytes into memory (needed because the archive
|
||||
/// borrows them), checks the directory (the entry count, unique and plain names, every part's
|
||||
/// A container being read. Opening reads all bytes into memory and checks the directory
|
||||
/// (the entry count, unique and plain names, every part's
|
||||
/// declared size), not the parts.
|
||||
pub struct Reader {
|
||||
/// The raw archive bytes, kept alive so the archive can borrow them.
|
||||
#[allow(dead_code)]
|
||||
bytes: Vec<u8>,
|
||||
archive: craft_zip::Archive<'static>,
|
||||
blobs: BTreeMap<String, Vec<u8>>,
|
||||
/// The bytes of payloads resolved so far, repeats counted: bounded by the expanded budget.
|
||||
@@ -202,13 +199,8 @@ impl Reader {
|
||||
let mut bytes = Vec::with_capacity(length as usize);
|
||||
source.read_to_end(&mut bytes).map_err(invalid)?;
|
||||
|
||||
// Leak the Vec to get 'static bytes (needed because Archive<'a> borrows them).
|
||||
// This is acceptable: Reader holds the bytes for its lifetime anyway, and
|
||||
// ZIP archives are typically small-to-moderate size.
|
||||
let leaked: &'static [u8] = Box::leak(bytes.into_boxed_slice());
|
||||
|
||||
let mut archive = craft_zip::Archive::open(
|
||||
leaked,
|
||||
let mut archive = craft_zip::Archive::open_owned(
|
||||
bytes,
|
||||
craft_zip::Limits { max_entries: limits.max_entries as u64, max_total_bytes: (limits.max_expanded)() as u64 },
|
||||
)
|
||||
.map_err(invalid)?;
|
||||
@@ -227,7 +219,7 @@ impl Reader {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self { bytes: leaked.to_vec(), archive, blobs: BTreeMap::new(), hydrated: 0, document: None, limits })
|
||||
Ok(Self { archive, blobs: BTreeMap::new(), hydrated: 0, document: None, limits })
|
||||
}
|
||||
|
||||
/// The file's own part, `document.json`, read once and kept: provisional caches and the
|
||||
|
||||
Reference in new issue
Block a user