From 482d4787db1fb8cf04d5e5b963d42de476c2c74f Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Tue, 16 Jul 2024 20:23:13 +0900 Subject: [PATCH] chore: use much early return --- src/stream.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/stream.rs b/src/stream.rs index 85bdd0f..dcb625b 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -45,6 +45,11 @@ impl Deflate64Decoder { impl Read for Deflate64Decoder { fn read(&mut self, buf: &mut [u8]) -> io::Result { + 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(); @@ -60,11 +65,6 @@ impl Read for Deflate64Decoder { )); } - 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