Skip to content

Commit 5a425ed

Browse files
committed
struct BzDecoder: document exit on error logic
1 parent dece038 commit 5a425ed

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/write.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,11 @@ impl<W: Write> Write for BzDecoder<W> {
254254
let res = self.data.decompress_vec(data, &mut self.buf);
255255
let written = (self.total_in() - before) as usize;
256256

257-
match res {
258-
Err(e) => {
259-
self.done = true;
260-
return Err(io::Error::new(io::ErrorKind::InvalidInput, e));
261-
}
262-
Ok(Status::StreamEnd) => {
263-
self.done = true;
264-
}
265-
Ok(_) => {}
257+
// make sure that a subsequent call exits early when there is nothing useful left to do
258+
self.done |= matches!(res, Err(_) | Ok(Status::StreamEnd));
259+
260+
if let Err(e) = res {
261+
return Err(io::Error::new(io::ErrorKind::InvalidInput, e));
266262
}
267263

268264
if written > 0 || data.is_empty() || self.done {
@@ -315,9 +311,9 @@ mod tests {
315311
assert_eq!(&data[..], b"");
316312
}
317313

318-
// https://github.com/alexcrichton/bzip2-rs/issues/98
319314
#[test]
320315
fn write_invalid() {
316+
// see https://github.com/trifectatechfoundation/bzip2-rs/issues/98
321317
let mut d = BzDecoder::new(Vec::new());
322318
let e = d.write(b"BZh\xfb").unwrap_err();
323319
assert_eq!(e.kind(), std::io::ErrorKind::InvalidInput);

0 commit comments

Comments
 (0)