Skip to main content

DecodeReuse

Enum DecodeReuse 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

pub const fn kind(self) -> DecodeReuseKind

The mode without its limit.

Trait Implementations§

Source§

impl Clone for DecodeReuse

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DecodeReuse

Source§

impl Debug for DecodeReuse

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DecodeReuse

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for DecodeReuse

Source§

impl PartialEq for DecodeReuse

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DecodeReuse

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.