incpush 0.1.1

Incrementally back up a big local folder to object storage (GCS/S3/Azure), uploading only changed files and preserving previous versions
Documentation
//! Small formatting helpers for human-facing output.

/// Format a byte count as a human-readable string (binary-ish, matching the
/// original tool's `kB, MB, ...` labels).
pub fn human_size(bytes: i64) -> String {
    let b = bytes as f64;
    if b.abs() < 1024.0 {
        return format!("{bytes} B");
    }
    let units = ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
    let mut val = b;
    let mut u = 0;
    loop {
        val /= 1024.0;
        if val.abs() < 1024.0 || u == units.len() - 1 {
            break;
        }
        u += 1;
    }
    format!("{:.1} {}", val, units[u])
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn formats_sizes() {
        assert_eq!(human_size(0), "0 B");
        assert_eq!(human_size(512), "512 B");
        assert_eq!(human_size(1024), "1.0 kB");
        assert_eq!(human_size(1536), "1.5 kB");
        assert_eq!(human_size(1024 * 1024), "1.0 MB");
        assert_eq!(human_size(5 * 1024 * 1024 * 1024), "5.0 GB");
    }
}