WriteFilter

Enum WriteFilter 

Source
#[non_exhaustive]
pub enum WriteFilter { None, BcjX86, BcjArm, BcjArm64, BcjArmThumb, BcjPpc, BcjSparc, BcjIa64, BcjRiscv, Bcj2, Delta { distance: u8, }, }
Expand description

Pre-compression filter for improving compression of specific data types.

BCJ (Branch/Call/Jump) filters transform executable code addresses from relative to absolute form before compression. This improves compression ratios by 5-15% for executable files because the resulting byte patterns compress better.

The Delta filter computes differences between consecutive samples, improving compression for audio, image, and other structured data.

§Example

use zesven::write::{WriteOptions, WriteFilter};

// Use BCJ x86 filter for compressing Windows/Linux executables
let options = WriteOptions::new().filter(WriteFilter::BcjX86);

// Use Delta filter for audio data (2-byte samples)
let options = WriteOptions::new().filter(WriteFilter::Delta { distance: 2 });

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.
§

None

No filter applied.

§

BcjX86

BCJ x86 filter for 32-bit and 64-bit x86 executables.

§

BcjArm

BCJ ARM filter for 32-bit ARM executables.

§

BcjArm64

BCJ ARM64/AArch64 filter for 64-bit ARM executables.

§

BcjArmThumb

BCJ ARM Thumb filter for ARM Thumb mode executables.

§

BcjPpc

BCJ PowerPC filter.

§

BcjSparc

BCJ SPARC filter.

§

BcjIa64

BCJ IA-64 (Itanium) filter.

§

BcjRiscv

BCJ RISC-V filter.

§

Bcj2

BCJ2 4-stream filter for x86 executables.

BCJ2 splits x86 code into 4 streams (main, call, jump, range) for improved compression. Unlike simple BCJ filters, BCJ2 uses a complex 4-input coder structure.

Note: BCJ2 is only supported in non-solid mode.

§

Delta

Delta filter for structured data (audio, images).

The distance parameter specifies the sample size in bytes. Common values:

  • 1: byte-level differences
  • 2: 16-bit audio samples
  • 4: 32-bit values or RGBA pixels

Use WriteFilter::delta() to construct with validation.

Fields

§distance: u8

Sample distance in bytes (1-255).

Implementations§

Source§

impl WriteFilter

Source

pub fn delta(distance: u8) -> Self

Creates a Delta filter with the given sample distance.

§Arguments
  • distance - Sample size in bytes (1-255)
§Panics

Panics if distance is 0. Use a non-zero distance value.

§Example
use zesven::write::WriteFilter;

let filter = WriteFilter::delta(2); // 16-bit samples
Source§

impl WriteFilter

Source

pub fn method_id(&self) -> Option<&'static [u8]>

Returns the 7z method ID bytes for this filter.

Source

pub fn is_bcj2(&self) -> bool

Returns whether this is the BCJ2 filter.

BCJ2 requires special handling as it produces 4 output streams.

Source

pub fn is_active(&self) -> bool

Returns whether this filter is active (not None).

Source

pub fn properties(&self) -> Option<Vec<u8>>

Returns the filter properties to encode in the archive header.

Most BCJ filters have no properties. Delta filter has a 1-byte property encoding distance - 1 (so distance 1 is stored as 0, distance 255 as 254).

Trait Implementations§

Source§

impl Clone for WriteFilter

Source§

fn clone(&self) -> WriteFilter

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for WriteFilter

Source§

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

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

impl Default for WriteFilter

Source§

fn default() -> WriteFilter

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

impl PartialEq for WriteFilter

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for WriteFilter

Source§

impl Eq for WriteFilter

Source§

impl StructuralPartialEq for WriteFilter

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.