Skip to main content

oci_core/core/
progress.rs

1use std::sync::Arc;
2use std::time::Duration;
3
4#[derive(Debug, Clone)]
5pub struct LayerProgressInit {
6    pub digest: String,
7    pub total_bytes: u64,
8    pub chunk_size_bytes: usize,
9    pub estimated_chunks: u64,
10}
11
12#[derive(Debug, Clone)]
13pub struct LayerProgressUpdate {
14    pub digest: String,
15    pub sent_bytes: u64,
16    pub total_bytes: u64,
17    pub elapsed: Duration,
18    pub speed_mbps: f64,
19    pub eta_seconds: Option<f64>,
20}
21
22#[derive(Debug, Clone)]
23pub struct LayerProgressComplete {
24    pub digest: String,
25    pub total_bytes: u64,
26    pub elapsed: Duration,
27    pub average_mbps: f64,
28}
29
30#[derive(Debug, Clone)]
31pub struct ChunkTransferEvent {
32    pub digest: String,
33    pub chunk_index: u64,
34    pub chunk_bytes: usize,
35    pub total_transferred: u64,
36    pub total_bytes: Option<u64>,
37}
38
39pub trait ProgressReporter: Send + Sync + 'static {
40    fn on_layer_start(&self, _info: LayerProgressInit) {}
41    fn on_layer_progress(&self, _update: LayerProgressUpdate) {}
42    fn on_layer_complete(&self, _summary: LayerProgressComplete) {}
43    fn on_chunk_transferred(&self, _chunk: ChunkTransferEvent) {}
44}
45
46pub type ProgressReporterHandle = Arc<dyn ProgressReporter>;