Skip to main content

ChunkEvent

Struct ChunkEvent 

Source
#[non_exhaustive]
pub struct ChunkEvent { pub index: usize, pub kind: [u8; 4], pub bytes_read: u64, }
Expand description

One chunk-applied event delivered to an ApplyObserver.

Fired after each top-level chunk’s apply has completed successfully. The index field is the zero-based ordinal of the chunk in the patch stream, counting every chunk yielded by ZiPatchReader (the internal EOF_ terminator is not yielded and is not counted). The kind is the 4-byte ASCII wire tag of the chunk, which lets the consumer categorise events without needing to match on the Chunk enum directly. bytes_read is the running total of bytes consumed from the patch stream up to and including this chunk’s frame (length prefix, tag, body, and CRC32).

§Stability

The struct is #[non_exhaustive]. New fields may be added in future minor versions. Construct in tests via the ChunkEvent::new associated function rather than struct-literal syntax.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§index: usize

Zero-based index of the chunk within the patch stream.

Counts every chunk yielded by ZiPatchReader, in stream order. The internal EOF_ terminator is not counted.

§kind: [u8; 4]

4-byte ASCII wire tag of the chunk (e.g. *b"SQPK", *b"ADIR").

EOF_ will never appear here because the reader consumes that chunk internally. New tags introduced by Square Enix would surface as ZiPatchError::UnknownChunkTag before any event fires for them.

§bytes_read: u64

Running total of bytes consumed from the patch stream, measured from the start of the patch file (including the 12-byte magic prefix).

Monotonically non-decreasing across successive events; equal to the stream position immediately after the chunk’s CRC32 was read. Useful for driving a bytes_applied / total_patch_size progress bar.

Implementations§

Source§

impl ChunkEvent

Source

pub fn new(index: usize, kind: [u8; 4], bytes_read: u64) -> Self

Construct a ChunkEvent from its component fields.

Primarily intended for unit-test fixtures. Production code receives events from the apply driver and does not need to construct them.

Source

pub fn kind_str(&self) -> Option<&str>

Returns the chunk’s kind tag as a &str if it is valid UTF-8.

All wire tags defined by the ZiPatch format are 4-byte ASCII (SQPK, ADIR, APLY, …), so this returns Some(&str) in practice. The fallible variant exists because the field type is [u8; 4], which by itself does not constrain the contents to UTF-8 — a forward-compatible future tag or a corrupt event constructed in tests could in principle carry non-ASCII bytes.

§Example
use zipatch_rs::ChunkEvent;
let ev = ChunkEvent::new(0, *b"SQPK", 96);
assert_eq!(ev.kind_str(), Some("SQPK"));

let bad = ChunkEvent::new(0, [0xFF, 0xFE, 0, 0], 0);
assert_eq!(bad.kind_str(), None);

Trait Implementations§

Source§

impl Clone for ChunkEvent

Source§

fn clone(&self) -> ChunkEvent

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 Debug for ChunkEvent

Source§

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

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

impl PartialEq for ChunkEvent

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 ChunkEvent

Source§

impl Eq for ChunkEvent

Source§

impl StructuralPartialEq for ChunkEvent

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more