diff --git a/src/write.rs b/src/write.rs index 5d80000e..b96ee77c 100644 --- a/src/write.rs +++ b/src/write.rs @@ -203,7 +203,8 @@ impl BzDecoder { /// /// [`write`]: Self::write pub fn try_finish(&mut self) -> io::Result<()> { - while !self.done { + // If nothing was written, there is no need to loop + while !self.done && self.total_in() > 0 { let _ = self.write(&[])?; } self.dump() @@ -309,6 +310,13 @@ mod tests { assert_eq!(&data[..], b""); } + #[test] + fn write_empty2() { + let mut d = BzDecoder::new(Vec::new()); + d.write(b"").unwrap(); + d.finish().unwrap(); + } + #[test] fn qc() { ::quickcheck::quickcheck(test as fn(_) -> _);