1use std::io::{self, Read};
2use std::path::Path;
3
4pub struct ProgressReader<'a, R> {
6 inner: R,
7 on_bytes: &'a (dyn Fn(u64) + Send + Sync),
8}
9
10impl<'a, R: Read> ProgressReader<'a, R> {
11 pub fn new(inner: R, on_bytes: &'a (dyn Fn(u64) + Send + Sync)) -> Self {
12 Self { inner, on_bytes }
13 }
14}
15
16impl<R: Read> Read for ProgressReader<'_, R> {
17 fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
18 let n = self.inner.read(buf)?;
19 if n > 0 {
20 (self.on_bytes)(n as u64);
21 }
22 Ok(n)
23 }
24}
25
26pub type OnFileStart = dyn Fn(&Path, u64) -> FileProgress + Send + Sync;
28
29pub struct FileProgress {
30 pub on_bytes: Box<dyn Fn(u64) + Send + Sync>,
32 pub on_done: Box<dyn Fn(bool) + Send + Sync>,
34}