Skip to content

Commit

Permalink
chore: use much early return
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Jul 16, 2024
1 parent a871673 commit 482d478
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ impl<R> Deflate64Decoder<R> {

impl<R: BufRead> Read for Deflate64Decoder<R> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
if buf.is_empty() {
// we received empty buffer, so it won't be possible to write anything
return Ok(0);
}

loop {
let input = self.inner.fill_buf()?;
let eof = input.is_empty();
Expand All @@ -60,11 +65,6 @@ impl<R: BufRead> Read for Deflate64Decoder<R> {
));
}

if buf.is_empty() {
// we received empty buffer, so it won't be possible to write anything
return Ok(0);
}

if result.bytes_written == 0 && !eof && !self.inflater.finished() {
// if we haven't ready any data and we haven't hit EOF yet,
// ask again. We must not return 0 in such case
Expand Down

0 comments on commit 482d478

Please sign in to comment.