1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use std::io::Write;

#[derive(Default)]
pub(crate) struct ByteCounter {
    bytes: usize,
}

impl ByteCounter {
    pub fn bytes(&self) -> usize {
        self.bytes
    }
}

impl Write for ByteCounter {
    fn write(&mut self, buf: &[u8]) -> Result<usize, std::io::Error> {
        self.bytes += buf.len();
        Ok(buf.len())
    }

    fn flush(&mut self) -> Result<(), std::io::Error> {
        Ok(())
    }
}