#[non_exhaustive]pub enum DecodeReuse {
Off,
Memory(ReuseLimit),
TempFile(ReuseLimit),
}Expand description
Where a ZIP extraction keeps decoded output between the structural check and the write, so a deflate entry is decoded once.
The check that refuses entry data past a stream end decodes each deflate entry, and extraction decodes it again. A kept entry is checked against its CRC-32 again when it is read back, so a damaged store is refused like a damaged archive, and an entry that was not kept is decoded from the archive as before.
The bytes kept never exceed the smallest of the mode’s ReuseLimit, the
config’s max_decoder_memory and its max_total_size, and an entry that
max_file_size or max_compression_ratio would refuse is not kept, so a
memory-capped container can lower max_decoder_memory to bound the cost.
Reuse applies to extractions that write into a directory
(extract_archive and
ListedArchive::extract). Sink and
callback extraction keeps output only when
SinkOptions::decode_reuse opts in, and
defaults to Off; listing and verification never keep output. Bzip2 and
zstd entries are always decoded twice.
An entry above the mode’s ReuseLimit is decoded twice whatever the mode
is: the default ReuseLimit::DEFAULT of 32 MiB leaves a larger member
decoded twice under extract_archive. With
TempFile the plaintext of the kept entries sits in the temporary
directory until the extraction ends, and the limit bounds only the store,
not the memory the entry being written uses on top of it.
§Examples
use exarch_core::DecodeReuse;
use exarch_core::ReuseLimit;
assert_eq!(
DecodeReuse::default(),
DecodeReuse::Memory(ReuseLimit::DEFAULT)
);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Off
Keep nothing; every entry is decoded twice.
Memory(ReuseLimit)
Keep decoded entries in memory, up to the limit.
Works on every target and writes nothing outside the destination.
TempFile(ReuseLimit)
Keep decoded entries in an unnamed temporary file, up to the limit.
The file lives in the platform’s temporary directory and holds the plaintext of the archive until the extraction ends. When no temporary file can be created, or on WASI, nothing is kept.
On Linux and Android a file that lands on a tmpfs or ramfs is detected
and charged like Memory: its length counts against
the shared decoder-memory budget, and when an extraction into a sink
needs room the latest kept entries are cut off the end of the file and
decoded again. The bytes of entries already extracted are not released
until the extraction ends, so a RAM-backed spool is charged
conservatively: evicting an entry below the one currently being read
frees nothing, because the file is never cut lower than that entry’s
end. The Linux detection is compiled and exercised only by CI; it has
not been run on a Linux host. On every other target the file is assumed
to be on disk, so a temporary directory that is a RAM disk (FreeBSD
tmpfs, a macOS RAM disk) holds the spool in memory outside the budget.
Writing the spool and reading it back is paid in kernel time on every
byte kept. Measured (2026-11, macOS, release CLI, a shared host at a
load average of 5 to 12, deflate ZIPs of 10 MiB members at a
compression ratio of about 2.2): 1.15x the wall time of the build
before decode reuse for an archive of 100 MiB decoded (a 47 MB ZIP)
and 1.18x for 300 MiB decoded (a 140 MB ZIP). Most of the excess is
system time; user time rose by about 0.05 s of the 0.13 s excess on the
larger archive. Memory measures 1.07x on the 100 MiB
one. Writing the decoder’s 256 KiB chunks to the file without the
64 KiB buffer measured no faster, and a memory-mapped spool is ruled
out by the crate’s unsafe ban, so this is the floor of the design.
Linux (ext4, tmpfs) is not measured.
The archive’s own listing pass for TAR, which also spools to a temporary file, is not charged to this budget.
Implementations§
Source§impl DecodeReuse
impl DecodeReuse
Sourcepub const fn kind(self) -> DecodeReuseKind
pub const fn kind(self) -> DecodeReuseKind
The mode without its limit.
Trait Implementations§
Source§impl Clone for DecodeReuse
impl Clone for DecodeReuse
impl Copy for DecodeReuse
Source§impl Debug for DecodeReuse
impl Debug for DecodeReuse
Source§impl Default for DecodeReuse
impl Default for DecodeReuse
impl Eq for DecodeReuse
Source§impl PartialEq for DecodeReuse
impl PartialEq for DecodeReuse
impl StructuralPartialEq for DecodeReuse
Auto Trait Implementations§
impl Freeze for DecodeReuse
impl RefUnwindSafe for DecodeReuse
impl Send for DecodeReuse
impl Sync for DecodeReuse
impl Unpin for DecodeReuse
impl UnsafeUnpin for DecodeReuse
impl UnwindSafe for DecodeReuse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.