Skip to main content

Par2FileSet

Struct Par2FileSet 

Source
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: RecoverySetId

The recovery set ID (MD5 of the main packet body).

§slice_size: u64

Block/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

Source

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.

Source

pub fn from_files_with_limits( par2_files: &[&[u8]], limits: PacketScanLimits, ) -> Result<Self>

Self::from_files under caller-chosen limits.

Source

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.

Source

pub fn from_paths_with_limits<P: AsRef<Path>>( par2_files: &[P], limits: PacketScanLimits, ) -> Result<Self>

Self::from_paths under caller-chosen limits.

Source

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.

Source

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.

Source

pub fn file_description(&self, file_id: &FileId) -> Option<&FileDescription>

Get the file description for a given file ID.

Source

pub fn file_checksums(&self, file_id: &FileId) -> Option<&[SliceChecksum]>

Get the slice checksums for a given file ID.

Source

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.

Source

pub fn recovery_files(&self) -> Vec<&FileDescription>

Return all file descriptions in the recovery set, in order.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> Par2FileSet

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 Par2FileSet

Source§

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

Formats the value using the given formatter. Read more

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 = !

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