pub fn pack_files<F>(
files: &[PathBuf],
config: &PackConfig,
on_progress: F,
) -> Result<()>Expand description
Compresses the provided list of files into a ZIP archive.
This function supports ZIP64 extensions, allowing it to handle files larger than 4GB.
It uses stream-based copying (std::io::copy) to keep memory usage low.
§Arguments
files- A slice of file paths to be compressed.root_path- The base path used to calculate relative paths inside the ZIP archive.output_path- The destination path for the generated ZIP file.on_progress- A closure called after each file is processed.- Arguments:
(path: &PathBuf, current_file_size: u64, total_processed_size: u64)
- Arguments:
§Returns
Result<()>- Returns Ok if the operation completes successfully.
§Example
use srcpack::{pack_files, ScanConfig, scan_files, PackConfig};
use std::path::Path;
let root = Path::new(".");
let config = ScanConfig::new(root, vec![]);
let files = scan_files(&config).unwrap(); // Get list of files first
let output = Path::new("backup.zip");
let pack_config = PackConfig {
root_path: root.to_path_buf(),
output_path: output.to_path_buf(),
compression_method: zip::CompressionMethod::Deflated,
compression_level: None,
};
// Pack the files with a simple progress closure
pack_files(&files, &pack_config, |path, size, total| {
println!("Packed {:?} ({} bytes)", path, size);
}).expect("Failed to pack files");