Skip to content

Commit

Permalink
add panicked flag to BzDecoder
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Dec 18, 2024
1 parent c2e93b1 commit 2353eed
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct BzDecoder<W: Write> {
obj: Option<W>,
buf: Vec<u8>,
done: bool,
panicked: bool,
}

impl<W: Write> BzEncoder<W> {
Expand Down Expand Up @@ -167,6 +168,7 @@ impl<W: Write> BzDecoder<W> {
obj: Some(obj),
buf: Vec::with_capacity(32 * 1024),
done: false,
panicked: false,
}
}

Expand All @@ -185,12 +187,15 @@ impl<W: Write> BzDecoder<W> {

fn dump(&mut self) -> io::Result<()> {
while !self.buf.is_empty() {
let n = match self.obj.as_mut().unwrap().write(&self.buf) {
Ok(n) => n,
self.panicked = true;
let r = self.obj.as_mut().unwrap().write(&self.buf);
self.panicked = false;

match r {
Ok(n) => self.buf.drain(..n),
Err(ref err) if err.kind() == io::ErrorKind::Interrupted => continue,
Err(err) => return Err(err),
};
self.buf.drain(..n);
}
Ok(())
}
Expand Down

0 comments on commit 2353eed

Please sign in to comment.