create_tar_with_progress

Function create_tar_with_progress 

Source
pub fn create_tar_with_progress<P: AsRef<Path>, Q: AsRef<Path>>(
    output: P,
    sources: &[Q],
    config: &CreationConfig,
    progress: &mut dyn ProgressCallback,
) -> Result<CreationReport>
Expand description

Creates an uncompressed TAR archive with progress reporting.

This function provides real-time progress updates during archive creation through callback functions. Useful for displaying progress bars or logging in interactive applications.

§Parameters

  • output: Path where the TAR archive will be created
  • sources: Slice of source paths to include in the archive
  • config: Configuration controlling filtering, permissions, and archiving behavior
  • progress: Mutable reference to a progress callback implementation

§Progress Callbacks

The progress callback receives four types of events:

  1. on_entry_start: Called before processing each file/directory
  2. on_bytes_written: Called for each chunk of data written (typically every 64 KB)
  3. on_entry_complete: Called after successfully processing an entry
  4. on_complete: Called once when the entire archive is finished

Note: Callbacks are invoked frequently during large file processing. For better performance with very large files, consider batching updates.

§Examples

use exarch_core::ProgressCallback;
use exarch_core::creation::CreationConfig;
use exarch_core::creation::tar::create_tar_with_progress;
use std::path::Path;

struct SimpleProgress;

impl ProgressCallback for SimpleProgress {
    fn on_entry_start(&mut self, path: &Path, total: usize, current: usize) {
        println!("[{}/{}] Processing: {}", current, total, path.display());
    }

    fn on_bytes_written(&mut self, bytes: u64) {
        // Called frequently - consider rate limiting
    }

    fn on_entry_complete(&mut self, path: &Path) {
        println!("Completed: {}", path.display());
    }

    fn on_complete(&mut self) {
        println!("Archive creation complete!");
    }
}

let config = CreationConfig::default();
let mut progress = SimpleProgress;
let report = create_tar_with_progress(
    Path::new("output.tar"),
    &[Path::new("src")],
    &config,
    &mut progress,
)?;

§Errors

Returns an error if:

  • Source path does not exist
  • Output file cannot be created
  • I/O error during archive creation
  • File metadata cannot be read