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,