mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +00:00
LibCore: Add Stream::read_all()
This commit is contained in:
parent
af50b0363b
commit
68772463cb
2 changed files with 17 additions and 0 deletions
|
@ -47,6 +47,22 @@ bool Stream::read_or_error(Bytes buffer)
|
|||
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)
|
||||
{
|
||||
VERIFY(buffer.size());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue