chdlady-core 0.1.0

Core container manipulation for CHD v5 format
//! Structured progress and operation tracking for CHD containers.

/// Operation phase being executed.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OperationPhase {
    /// Examining / indexing parent units in differential CHD creation.
    ExaminingParent,
    /// Compressing hunks into the CHD container.
    Compressing,
    /// Extracting / decompressing data from a CHD container.
    Extracting,
    /// Verifying checksums across container hunks.
    Verifying,
}

/// Status update emitted periodically during container operations.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ProgressStatus {
    /// The active operation phase.
    pub phase: OperationPhase,
    /// Progress counter (e.g. hunk index, byte offset, or frame index).
    pub current: u64,
    /// Total items or bytes expected in the operation.
    pub total: u64,
    /// Instantaneous or overall compression ratio [0.0..], if applicable.
    pub ratio: Option<f64>,
}

impl ProgressStatus {
    /// Creates a new progress status update.
    pub const fn new(phase: OperationPhase, current: u64, total: u64, ratio: Option<f64>) -> Self {
        Self {
            phase,
            current,
            total,
            ratio,
        }
    }

    /// Computes completion percentage [0.0, 100.0].
    pub fn percent(&self) -> f64 {
        if self.total == 0 {
            100.0
        } else {
            100.0 * (self.current as f64 / self.total as f64)
        }
    }
}