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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//! 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:
//! - [`Progress`] - Immutable snapshot of current progress
//! - [`ProgressCallback`] - Trait for receiving progress updates
//! - [`PrintProgressCallback`] - Built-in stdout progress logger
//!
//! # Usage
//!
//! Progress callbacks are optional and can be passed to streaming methods
//! like [`FileHandler::upload_stream()`](crate::files::FileHandler::upload_stream)
//! and [`FileHandler::download_stream()`](crate::files::FileHandler::download_stream).
//!
//! ## Basic Example
//!
//! ```rust
//! 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);
//! }
//! }
//! }
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! # use files_sdk::{FilesClient, files::FileHandler};
//! # let client = FilesClient::builder().api_key("key").build()?;
//! 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?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Advanced Example with State
//!
//! ```rust
//! 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);
//! }
//! }
//! }
//! ```
/// Progress information for a file operation
/// Trait for receiving progress updates during file operations
///
/// Implement this trait to receive callbacks as data is transferred.
///
/// # Examples
///
/// ```rust
/// use files_sdk::progress::{Progress, ProgressCallback};
///
/// struct MyProgressTracker;
///
/// impl ProgressCallback for MyProgressTracker {
/// fn on_progress(&self, progress: &Progress) {
/// if let Some(pct) = progress.percentage() {
/// println!("Progress: {:.1}%", pct);
/// } else {
/// println!("Transferred: {} bytes", progress.bytes_transferred);
/// }
/// }
/// }
/// ```
/// A simple progress callback that prints to stdout
;