image-optimizer 1.3.0

CLI tool for optimizing images (JPEG, PNG, WebP)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use anyhow::Result;
use std::ffi::OsStr;
use std::path::Path;

/// Creates a backup file by copying the original with a .bak extension
///
/// # Errors
/// Returns an error if the file copy operation fails
pub fn create_backup(file_path: &Path) -> Result<()> {
    let backup_path = file_path.with_extension(format!(
        "{}.bak",
        file_path.extension().and_then(OsStr::to_str).unwrap_or("")
    ));
    std::fs::copy(file_path, backup_path)?;
    Ok(())
}