From bb8c2273d4080eaa3cea4f9fd386230adceffbc9 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 9 Feb 2025 02:02:55 +0200 Subject: [PATCH] remove unspecified condition, skip handle the chunk on zero bytes received --- src/gio/memory_input_stream.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gio/memory_input_stream.rs b/src/gio/memory_input_stream.rs index c588f9d..2500087 100644 --- a/src/gio/memory_input_stream.rs +++ b/src/gio/memory_input_stream.rs @@ -55,9 +55,16 @@ pub fn for_memory_input_stream_async( Ok(bytes) => { let len = bytes.len(); // calculate once + // is the end of stream + if len == 0 { + return on_complete(Ok((memory_input_stream, total))); + } + + // handle the chunk total += len; on_chunk(len, total); + // push bytes into the memory pool memory_input_stream.add_bytes(&bytes); // prevent memory overflow on size `limit` reached @@ -67,13 +74,6 @@ pub fn for_memory_input_stream_async( return on_complete(Err(Error::BytesTotal(memory_input_stream, total, limit))); } - // is the next iteration required? - if len < chunk // some servers may close the connection after first chunk request (@TODO this condition wants review) - || len == 0 - { - return on_complete(Ok((memory_input_stream, total))); - } - // continue reading.. for_memory_input_stream_async( memory_input_stream,