1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use Result;
use ;
/// Ensures the output directory structure exists and returns the output file path.
///
/// This function creates the necessary directory structure in the output directory
/// to mirror the input directory structure, then returns the full path where the
/// optimized file should be written.
///
/// # Arguments
///
/// * `output_path` - Base output directory path
/// * `input_path` - Base input directory path (used to calculate relative paths)
/// * `file_path` - Path to the specific file being processed
///
/// # Returns
///
/// Returns the full `PathBuf` where the optimized file should be written.
///
/// # Errors
///
/// Returns an error if:
/// - Path stripping fails (`file_path` is not under `input_path`)
/// - Directory creation fails due to permissions or I/O errors
///
/// # Examples
///
/// ```rust
/// use std::path::Path;
/// use image_optimizer::file_ops::ensure_output_dir;
///
/// # fn example() -> anyhow::Result<()> {
/// let output_dir = Path::new("./optimized");
/// let input_dir = Path::new("./photos");
/// let file_path = Path::new("./photos/subfolder/image.jpg");
///
/// let output_file = ensure_output_dir(output_dir, input_dir, file_path)?;
/// // Returns: "./optimized/subfolder/image.jpg"
/// # Ok(())
/// # }
/// ```