pub struct Par2FileSet {
pub recovery_set_id: RecoverySetId,
pub slice_size: u64,
pub recovery_file_ids: Vec<FileId>,
pub non_recovery_file_ids: Vec<FileId>,
pub files: HashMap<FileId, FileDescription>,
pub slice_checksums: HashMap<FileId, Vec<SliceChecksum>>,
pub recovery_slices: BTreeMap<RecoveryExponent, RecoverySlice>,
pub creator: Option<String>,
}Expand description
Aggregated state from one or more .par2 files.
Collects Main, FileDescription, IFSC, RecoverySlice, and Creator packets into a unified view of the PAR2 recovery set.
Fields§
§recovery_set_id: RecoverySetIdThe recovery set ID (MD5 of the main packet body).
slice_size: u64Block/slice size in bytes.
recovery_file_ids: Vec<FileId>File IDs that are in the recovery set (order matters for RS coding).
non_recovery_file_ids: Vec<FileId>File IDs that are NOT in the recovery set.
files: HashMap<FileId, FileDescription>File descriptions keyed by file ID.
slice_checksums: HashMap<FileId, Vec<SliceChecksum>>Slice checksums (IFSC data) keyed by file ID.
recovery_slices: BTreeMap<RecoveryExponent, RecoverySlice>Recovery slices keyed by exponent.
creator: Option<String>Creator application identifier, if found.
Implementations§
Source§impl Par2FileSet
impl Par2FileSet
Sourcepub fn from_files(par2_files: &[&[u8]]) -> Result<Self>
pub fn from_files(par2_files: &[&[u8]]) -> Result<Self>
Create a new Par2FileSet by parsing packets from one or more .par2 file contents.
Each element of par2_files is the raw bytes of a .par2 file. Packets
stream straight into the builder, which deduplicates as it goes, so the
peak is the deduplicated inventory rather than the packet stream. One
PacketScanBudget spans every input, under the default limits.
Sourcepub fn from_files_with_limits(
par2_files: &[&[u8]],
limits: PacketScanLimits,
) -> Result<Self>
pub fn from_files_with_limits( par2_files: &[&[u8]], limits: PacketScanLimits, ) -> Result<Self>
Self::from_files under caller-chosen limits.
Sourcepub fn from_paths<P: AsRef<Path>>(par2_files: &[P]) -> Result<Self>
pub fn from_paths<P: AsRef<Path>>(par2_files: &[P]) -> Result<Self>
Create a new Par2FileSet by parsing packets directly from one or more on-disk .par2 files. Recovery slice payloads are kept file-backed.
Sourcepub fn from_paths_with_limits<P: AsRef<Path>>(
par2_files: &[P],
limits: PacketScanLimits,
) -> Result<Self>
pub fn from_paths_with_limits<P: AsRef<Path>>( par2_files: &[P], limits: PacketScanLimits, ) -> Result<Self>
Self::from_paths under caller-chosen limits.
Sourcepub fn from_files_with_diagnostics(
par2_files: &[&[u8]],
) -> Result<Par2ParseResult>
pub fn from_files_with_diagnostics( par2_files: &[&[u8]], ) -> Result<Par2ParseResult>
Create a Par2FileSet with diagnostic information about parse errors.
Unlike Self::from_files, this does not fail on individual file parse errors.
Instead, errors are collected into Par2Diagnostic. Returns an error
only if no valid main packet was found across all files — or if the
shared budget is exhausted, which is never downgraded to a diagnostic
because a partial inventory is indistinguishable from a small one.
Sourcepub fn from_packets(packets: Vec<Packet>) -> Result<Self>
pub fn from_packets(packets: Vec<Packet>) -> Result<Self>
Create from an already-parsed list of packets.
The caller already holds the packets, so this charges only the builder’s own retention against a default budget.
Sourcepub fn file_description(&self, file_id: &FileId) -> Option<&FileDescription>
pub fn file_description(&self, file_id: &FileId) -> Option<&FileDescription>
Get the file description for a given file ID.
Sourcepub fn file_checksums(&self, file_id: &FileId) -> Option<&[SliceChecksum]>
pub fn file_checksums(&self, file_id: &FileId) -> Option<&[SliceChecksum]>
Get the slice checksums for a given file ID.
Sourcepub fn expected_file_crc32(&self, file_id: FileId) -> Option<u32>
pub fn expected_file_crc32(&self, file_id: FileId) -> Option<u32>
Return the CRC32 expected for the unpadded bytes of a file.
PAR2 IFSC records store the CRC32 for each full input slice. A short final slice is zero-padded before its IFSC checksum is calculated, so its padding must be removed in GF(2) before the per-slice CRCs can be combined into the file’s actual CRC32. Missing or internally inconsistent metadata produces no value.
Sourcepub fn recovery_files(&self) -> Vec<&FileDescription>
pub fn recovery_files(&self) -> Vec<&FileDescription>
Return all file descriptions in the recovery set, in order.
Sourcepub fn recovery_block_count(&self) -> u32
pub fn recovery_block_count(&self) -> u32
Number of recovery blocks available.
An upper bound for a set loaded from disk: the path scanner records recovery payloads as file-backed spans without hashing them, so a block whose payload is damaged is still counted here. It drops out only when something validates its packet hash, which repair does before using it.
Sourcepub fn merge_packets(&mut self, packets: Vec<Packet>) -> Result<MergeResult>
pub fn merge_packets(&mut self, packets: Vec<Packet>) -> Result<MergeResult>
Merge additional packets into this file set.
Used to add recovery slices from newly-downloaded PAR2 volumes. Ignores duplicate packets. Returns error if a conflicting recovery set ID is encountered.
Sourcepub fn slice_count_for_file(&self, file_length: u64) -> u32
pub fn slice_count_for_file(&self, file_length: u64) -> u32
Compute the number of slices for a file given its length and the slice size.
Uses checked arithmetic to avoid overflow on malicious inputs.
Returns 0 for zero-length files and caps at u32::MAX (the PAR2 spec
uses 32-bit slice indices, so files larger than slice_size * u32::MAX
are already outside spec).
Trait Implementations§
Source§impl Clone for Par2FileSet
impl Clone for Par2FileSet
Source§fn clone(&self) -> Par2FileSet
fn clone(&self) -> Par2FileSet
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for Par2FileSet
impl RefUnwindSafe for Par2FileSet
impl Send for Par2FileSet
impl Sync for Par2FileSet
impl Unpin for Par2FileSet
impl UnsafeUnpin for Par2FileSet
impl UnwindSafe for Par2FileSet
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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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