@@ -25,10 +25,10 @@ use crate::Progress;
25
25
/// The progress callback will never overshoot.
26
26
pub struct TrackProgressReader < R , F > {
27
27
inner : R ,
28
- loaded : u64 ,
29
- approximate_total : u64 ,
30
28
on_progress : F ,
31
29
complete_on_drop : bool ,
30
+ loaded_bytes : u64 ,
31
+ approximate_total_bytes : u64 ,
32
32
}
33
33
34
34
/// A byte writer, like a file or a network stream.
@@ -38,10 +38,10 @@ pub struct TrackProgressReader<R, F> {
38
38
/// The progress callback will never overshoot.
39
39
pub struct TrackProgressWriter < R , F > {
40
40
inner : R ,
41
- loaded : u64 ,
42
- approximate_total : u64 ,
43
41
on_progress : F ,
44
42
complete_on_drop : bool ,
43
+ written_bytes : u64 ,
44
+ approximate_total_bytes : u64 ,
45
45
}
46
46
47
47
impl < F > TrackProgressReader < File , F > {
@@ -52,9 +52,9 @@ impl<F> TrackProgressReader<File, F> {
52
52
Self {
53
53
on_progress,
54
54
inner : file,
55
- approximate_total : file. metadata ( ) ?. len ( ) ,
55
+ approximate_total_bytes : file. metadata ( ) ?. len ( ) ,
56
56
complete_on_drop : true ,
57
- loaded : 0 ,
57
+ loaded_bytes : 0 ,
58
58
}
59
59
}
60
60
}
@@ -65,9 +65,9 @@ impl<R: Read, F> TrackProgressReader<R, F> {
65
65
Self {
66
66
on_progress,
67
67
inner,
68
- approximate_total : file_size,
68
+ approximate_total_bytes : file_size,
69
69
complete_on_drop : true ,
70
- loaded : 0 ,
70
+ loaded_bytes : 0 ,
71
71
}
72
72
}
73
73
@@ -78,7 +78,7 @@ impl<R: Read, F> TrackProgressReader<R, F> {
78
78
79
79
/// Called after meta data was read, but before reading the content of the file.
80
80
pub fn update_expected_size ( & mut self , file_size : u64 ) {
81
- self . approximate_total = file_size;
81
+ self . approximate_total_bytes = file_size;
82
82
}
83
83
}
84
84
@@ -88,9 +88,9 @@ impl<W: Write, F> TrackProgressWriter<W, F> {
88
88
Self {
89
89
inner,
90
90
on_progress,
91
- approximate_total : estimated_compressed_file_size,
91
+ approximate_total_bytes : estimated_compressed_file_size,
92
92
complete_on_drop : true ,
93
- loaded : 0 ,
93
+ written_bytes : 0 ,
94
94
}
95
95
}
96
96
@@ -108,8 +108,8 @@ impl<R,F> Read for TrackProgressReader<R, F>
108
108
109
109
if let Some ( & count) = & result {
110
110
// report progress of the bytes that have definitely been processed
111
- self . on_progress ( new_progress ( self . loaded , self . approximate_total ) ) ;
112
- self . loaded += count;
111
+ self . on_progress ( new_progress ( self . loaded_bytes , self . approximate_total_bytes ) ) ;
112
+ self . loaded_bytes += count;
113
113
}
114
114
115
115
result
@@ -124,10 +124,10 @@ impl<W,F> Write for TrackProgressWriter<W, F>
124
124
let result = self . inner . write ( buffer) ;
125
125
126
126
if let Some ( & count) = & result {
127
- self . loaded += count;
127
+ self . written_bytes += count;
128
128
129
129
// report progress of written state
130
- self . on_progress ( new_progress ( self . loaded , self . approximate_total ) ) ;
130
+ self . on_progress ( new_progress ( self . written_bytes , self . approximate_total_bytes ) ) ;
131
131
}
132
132
133
133
result
@@ -141,15 +141,15 @@ impl<W,F> Write for TrackProgressWriter<W, F>
141
141
impl < R , F : FnMut ( Progress ) > Drop for TrackProgressReader < R , F > {
142
142
fn drop ( & mut self ) {
143
143
if self . complete_on_drop {
144
- self . on_progress ( complete_progress ( self . approximate_total ) )
144
+ self . on_progress ( complete_progress ( self . approximate_total_bytes ) )
145
145
}
146
146
}
147
147
}
148
148
149
149
impl < W , F : FnMut ( Progress ) > Drop for TrackProgressWriter < W , F > {
150
150
fn drop ( & mut self ) {
151
151
if self . complete_on_drop {
152
- self . on_progress ( complete_progress ( self . approximate_total ) )
152
+ self . on_progress ( complete_progress ( self . approximate_total_bytes ) )
153
153
}
154
154
}
155
155
}
0 commit comments