File tree Expand file tree Collapse file tree 2 files changed +6
-1
lines changed
Userland/Libraries/LibCore Expand file tree Collapse file tree 2 files changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,9 @@ ErrorOr<void> Stream::discard(size_t discarded_bytes)
82
82
Array<u8 , continuous_read_size> buffer;
83
83
84
84
while (discarded_bytes > 0 ) {
85
+ if (is_eof ())
86
+ return Error::from_string_literal (" Reached end-of-file before reading all discarded bytes" );
87
+
85
88
auto slice = TRY (read (buffer.span ().slice (0 , min (discarded_bytes, continuous_read_size))));
86
89
discarded_bytes -= slice.size ();
87
90
}
Original file line number Diff line number Diff line change @@ -40,7 +40,9 @@ class Stream {
40
40
// / is returned once EOF is encountered. The block size determines the size
41
41
// / of newly allocated chunks while reading.
42
42
virtual ErrorOr<ByteBuffer> read_until_eof (size_t block_size = 4096 );
43
- // / Discards the given number of bytes from the stream.
43
+ // / Discards the given number of bytes from the stream. As this is usually used
44
+ // / as an efficient version of `read_entire_buffer`, it returns an error
45
+ // / if reading failed or if not all bytes could be discarded.
44
46
// / Unless specifically overwritten, this just uses read() to read into an
45
47
// / internal stack-based buffer.
46
48
virtual ErrorOr<void > discard (size_t discarded_bytes);
You can’t perform that action at this time.
0 commit comments