mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibCore: Make not discarding all requested bytes from a stream an error
This commit is contained in:
parent
9a3e95785e
commit
3fccf2481c
Notes:
sideshowbarker
2024-07-17 06:00:02 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/3fccf2481c Pull-request: https://github.com/SerenityOS/serenity/pull/16429 Reviewed-by: https://github.com/sin-ack ✅
2 changed files with 6 additions and 1 deletions
|
@ -82,6 +82,9 @@ ErrorOr<void> Stream::discard(size_t discarded_bytes)
|
|||
Array<u8, continuous_read_size> buffer;
|
||||
|
||||
while (discarded_bytes > 0) {
|
||||
if (is_eof())
|
||||
return Error::from_string_literal("Reached end-of-file before reading all discarded bytes");
|
||||
|
||||
auto slice = TRY(read(buffer.span().slice(0, min(discarded_bytes, continuous_read_size))));
|
||||
discarded_bytes -= slice.size();
|
||||
}
|
||||
|
|
|
@ -40,7 +40,9 @@ public:
|
|||
/// is returned once EOF is encountered. The block size determines the size
|
||||
/// of newly allocated chunks while reading.
|
||||
virtual ErrorOr<ByteBuffer> read_until_eof(size_t block_size = 4096);
|
||||
/// Discards the given number of bytes from the stream.
|
||||
/// Discards the given number of bytes from the stream. As this is usually used
|
||||
/// as an efficient version of `read_entire_buffer`, it returns an error
|
||||
/// if reading failed or if not all bytes could be discarded.
|
||||
/// Unless specifically overwritten, this just uses read() to read into an
|
||||
/// internal stack-based buffer.
|
||||
virtual ErrorOr<void> discard(size_t discarded_bytes);
|
||||
|
|
Loading…
Reference in a new issue