MCPcopy Create free account
hub / github.com/PerroEngine/Perro / ensure_inside_dir

Function ensure_inside_dir

perro_source/io_stack/perro_io/src/zip.rs:89–101  ·  view source on GitHub ↗
(root: &Path, target: &Path)

Source from the content-addressed store, hash-verified

87 read_zip_file_entry_with_limits(path, name, ZipLimits::default())
88}
89
90pub fn read_zip_file_entry_with_limits(
91 path: impl AsRef<Path>,
92 name: &str,
93 limits: ZipLimits,
94) -> io::Result<Vec<u8>> {
95 let file = fs::File::open(path)?;
96 let mut archive = zip::ZipArchive::new(file).map_err(zip_error_to_io)?;
97 check_entry_count(archive.len(), limits)?;
98 let mut entry = archive.by_name(name).map_err(zip_error_to_io)?;
99 check_entry_metadata(&entry, limits)?;
100 let byte_limit = limits.max_entry_bytes.min(limits.max_total_bytes);
101 let capacity = usize::try_from(entry.size().min(byte_limit)).unwrap_or(usize::MAX);
102 let mut out = Vec::new();
103 out.try_reserve(capacity)
104 .map_err(|err| io::Error::other(format!("zip entry allocation failed: {err}")))?;

Callers 1

extract_zip_fileFunction · 0.85

Calls 1

parentMethod · 0.80

Tested by

no test coverage detected