mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-03 22:59:33 +00:00
LibCore: Add Stream::read_all()
This commit is contained in:
parent
af50b0363b
commit
68772463cb
Notes:
sideshowbarker
2024-07-17 10:43:37 +09:00
Author: https://github.com/msvisser
Commit: 68772463cb
Pull-request: https://github.com/SerenityOS/serenity/pull/13384
Reviewed-by: https://github.com/Lubrsi
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/creator1creeper1
Reviewed-by: https://github.com/kleinesfilmroellchen ✅
2 changed files with 17 additions and 0 deletions
|
@ -47,6 +47,22 @@ bool Stream::read_or_error(Bytes buffer)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<ByteBuffer> Stream::read_all()
|
||||||
|
{
|
||||||
|
ByteBuffer output;
|
||||||
|
u8 buffer_raw[4096];
|
||||||
|
Bytes buffer { buffer_raw, 4096 };
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
Bytes read_bytes = TRY(read(buffer));
|
||||||
|
if (read_bytes.is_empty())
|
||||||
|
break;
|
||||||
|
output.append(read_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
bool Stream::write_or_error(ReadonlyBytes buffer)
|
bool Stream::write_or_error(ReadonlyBytes buffer)
|
||||||
{
|
{
|
||||||
VERIFY(buffer.size());
|
VERIFY(buffer.size());
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
/// Tries to fill the entire buffer through reading. Returns whether the
|
/// Tries to fill the entire buffer through reading. Returns whether the
|
||||||
/// buffer was filled without an error.
|
/// buffer was filled without an error.
|
||||||
virtual bool read_or_error(Bytes);
|
virtual bool read_or_error(Bytes);
|
||||||
|
ErrorOr<ByteBuffer> read_all();
|
||||||
|
|
||||||
virtual bool is_writable() const { return false; }
|
virtual bool is_writable() const { return false; }
|
||||||
/// Tries to write the entire contents of the buffer. It is possible for
|
/// Tries to write the entire contents of the buffer. It is possible for
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue