Skip to content

Commit

Permalink
Add AsyncBufRead implementation for ProgressBarIter (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
x0f5c3 committed Oct 11, 2021
1 parent c9425b6 commit 5930988
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/iter.rs
Expand Up @@ -200,6 +200,24 @@ impl<W: tokio::io::AsyncSeek + Unpin> tokio::io::AsyncSeek for ProgressBarIter<W
}
}

#[cfg(feature = "tokio")]
impl<W: tokio::io::AsyncBufRead + Unpin + tokio::io::AsyncRead> tokio::io::AsyncBufRead
for ProgressBarIter<W>
{
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
let this = self.get_mut();
let result = Pin::new(&mut this.it).poll_fill_buf(cx);
if let Poll::Ready(Ok(buf)) = &result {
this.progress.inc(buf.len() as u64);
}
result
}

fn consume(mut self: Pin<&mut Self>, amt: usize) {
Pin::new(&mut self.it).consume(amt);
}
}

impl<W: io::Write> io::Write for ProgressBarIter<W> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.it.write(buf).map(|inc| {
Expand Down

0 comments on commit 5930988

Please sign in to comment.