Module progress

Module progress 

Source
Expand description

Progress tracking for file operations

This module provides traits and types for tracking progress during file uploads and downloads with the streaming API.

§Overview

The progress tracking system consists of:

§Usage

Progress callbacks are optional and can be passed to streaming methods like FileHandler::upload_stream() and FileHandler::download_stream().

§Basic Example

use files_sdk::progress::{Progress, ProgressCallback};
use std::sync::Arc;

// Simple progress tracker
struct SimpleTracker;

impl ProgressCallback for SimpleTracker {
    fn on_progress(&self, progress: &Progress) {
        if let Some(pct) = progress.percentage() {
            println!("Upload: {:.1}%", pct);
        }
    }
}

let handler = FileHandler::new(client);
let callback = Arc::new(SimpleTracker);

// Use with streaming upload
let file = tokio::fs::File::open("large-file.bin").await?;
let size = file.metadata().await?.len() as i64;
handler.upload_stream("/remote/path.bin", file, Some(size), Some(callback)).await?;

§Advanced Example with State

use files_sdk::progress::{Progress, ProgressCallback};
use std::sync::{Arc, Mutex};
use std::time::Instant;

// Progress tracker with transfer rate calculation
struct RateTracker {
    start: Instant,
    last_bytes: Arc<Mutex<u64>>,
}

impl RateTracker {
    fn new() -> Self {
        Self {
            start: Instant::now(),
            last_bytes: Arc::new(Mutex::new(0)),
        }
    }
}

impl ProgressCallback for RateTracker {
    fn on_progress(&self, progress: &Progress) {
        let elapsed = self.start.elapsed().as_secs_f64();
        let rate = progress.bytes_transferred as f64 / elapsed / 1024.0 / 1024.0;

        if let Some(pct) = progress.percentage() {
            println!("Progress: {:.1}% @ {:.2} MB/s", pct, rate);
        }
    }
}

Structs§

PrintProgressCallback
A simple progress callback that prints to stdout
Progress
Progress information for a file operation

Traits§

ProgressCallback
Trait for receiving progress updates during file operations