chapter-tgz 0.1.0

Specially crafted .tar.gz with embedded chapter boundary information
Documentation
use std::io::{Result, Write};

pub(crate) struct Count<W> {
    out: W,
    written: u64,
}

impl<W> Count<W> {
    pub(crate) fn new(out: W) -> Self {
        Count { out, written: 0 }
    }

    pub(crate) fn position(&self) -> u64 {
        self.written
    }

    pub(crate) fn into_inner(self) -> W {
        self.out
    }
}

impl<W: Write> Write for Count<W> {
    fn write(&mut self, buf: &[u8]) -> Result<usize> {
        let n = self.out.write(buf)?;
        self.written = self.written.strict_add(u64::try_from(n).unwrap());
        Ok(n)
    }

    fn flush(&mut self) -> Result<()> {
        self.out.flush()
    }
}