mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 09:45:06 +02:00
LibCore+Everywhere: Make Core::Stream::read() return Bytes
A mistake I've repeatedly made is along these lines: ```c++ auto nread = TRY(source_file->read(buffer)); TRY(destination_file->write(buffer)); ``` It's a little clunky to have to create a Bytes or StringView from the buffer's data pointer and the nread, and easy to forget and just use the buffer. So, this patch changes the read() function to return a Bytes of the data that were just read. The other read_foo() methods will be modified in the same way in subsequent commits. Fixes #13687
This commit is contained in:
Notes:
sideshowbarker
2024-07-18 03:20:18 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/3b1e063d30 Pull-request: https://github.com/SerenityOS/serenity/pull/13694 Reviewed-by: https://github.com/trflynn89
@@ -56,8 +56,8 @@ void WebSocketImpl::connect(ConnectionInfo const& connection_info)
|
||||
ErrorOr<ByteBuffer> WebSocketImpl::read(int max_size)
|
||||
{
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(max_size));
|
||||
auto nread = TRY(m_socket->read(buffer));
|
||||
return buffer.slice(0, nread);
|
||||
auto read_bytes = TRY(m_socket->read(buffer));
|
||||
return buffer.slice(0, read_bytes.size());
|
||||
}
|
||||
|
||||
ErrorOr<String> WebSocketImpl::read_line(size_t size)
|
||||
|
||||
Reference in New Issue
Block a user