create_backup

Function create_backup 

Source
pub fn create_backup(file_path: &Path) -> Result<()>
Expand description

Creates a backup file by copying the original with a .bak extension.

This function creates a safety backup of the original file before optimization by copying it to a new file with the same name but with .bak appended to the extension. For example, image.jpg becomes image.jpg.bak.

§Arguments

  • file_path - Path to the file to backup

§Returns

Returns Ok(()) on successful backup creation.

§Errors

Returns an error if the file copy operation fails due to:

  • Insufficient disk space
  • Permission issues
  • I/O errors during file copying

§Examples

use std::path::Path;
use image_optimizer::file_ops::create_backup;

let file_path = Path::new("image.jpg");
create_backup(file_path)?; // Creates image.jpg.bak