diff options
author | Sven Gothel <[email protected]> | 2022-08-02 06:55:31 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-08-02 06:55:31 +0200 |
commit | b01d1571bd707e1c7ebacce3cd959ec3f6f8c710 (patch) | |
tree | 0de8b65bb825012c5e30930e4f7691868f8b0f1d /src/io_util.cpp | |
parent | 1a5e5b552ef6922d2f3a814862c2b13bbeb1b93b (diff) |
jau::io::read_stream(): Guarantee consumer_fn() is called with `is_final=true` once at the end, even if input stream has zero size
Diffstat (limited to 'src/io_util.cpp')
-rw-r--r-- | src/io_util.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/io_util.cpp b/src/io_util.cpp index 724e51e..7b43520 100644 --- a/src/io_util.cpp +++ b/src/io_util.cpp @@ -61,8 +61,8 @@ uint64_t jau::io::read_stream(ByteInStream& in, secure_vector<uint8_t>& buffer, StreamConsumerFunc consumer_fn) noexcept { uint64_t total = 0; - bool has_more = !in.end_of_data(); - while( has_more ) { + bool has_more; + do { if( in.check_available(1) ) { // at least one byte to stream .. buffer.resize(buffer.capacity()); const uint64_t got = in.read(buffer.data(), buffer.capacity()); @@ -83,7 +83,7 @@ uint64_t jau::io::read_stream(ByteInStream& in, buffer.resize(0); consumer_fn(buffer, true); // forced final, zero size } - } + } while( has_more ); return total; } |