#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.index: usizeZero-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: u64Running 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
impl ChunkEvent
Sourcepub fn new(index: usize, kind: [u8; 4], bytes_read: u64) -> Self
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.
Sourcepub fn kind_str(&self) -> Option<&str>
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
impl Clone for ChunkEvent
Source§fn clone(&self) -> ChunkEvent
fn clone(&self) -> ChunkEvent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ChunkEvent
impl Debug for ChunkEvent
Source§impl PartialEq for ChunkEvent
impl PartialEq for ChunkEvent
Source§fn eq(&self, other: &ChunkEvent) -> bool
fn eq(&self, other: &ChunkEvent) -> bool
self and other values to be equal, and is used by ==.