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
use crateCounter;
use ;
/// Wrapper around a `Read` that reports the progress made.
///
/// Used to monitor a file downloading or other slow IO task
/// in a progress bar.
///
/// # Examples
///
/// ```rust,no_run
/// use cursive_core::utils::{Counter, ProgressReader};
/// use std::io::Read;
///
/// // Read a file and report the progress
/// let file = std::fs::File::open("large_file").unwrap();
/// let counter = Counter::new(0);
/// let mut reader = ProgressReader::new(counter.clone(), file);
///
/// std::thread::spawn(move || {
/// // Left as an exercise: use an AtomicBool for a stop condition!
/// loop {
/// let progress = counter.get();
/// println!("Read {} bytes so far", progress);
/// }
/// });
///
/// // As we read data, the counter will be updated and the control thread
/// // will monitor the progress.
/// let mut buffer = Vec::new();
/// reader.read_to_end(&mut buffer).unwrap();
/// ```