mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 12:49:19 +00:00
LibCore: Add a basic wrapper for adapting AK::Stream to Core::Stream
This commit is contained in:
parent
6daef6303a
commit
7a065513cd
Notes:
sideshowbarker
2024-07-17 03:56:29 +09:00
Author: https://github.com/timschumi
Commit: 7a065513cd
Pull-request: https://github.com/SerenityOS/serenity/pull/16241
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/sin-ack ✅
Reviewed-by: https://github.com/trflynn89
2 changed files with 96 additions and 0 deletions
|
@ -714,4 +714,72 @@ ErrorOr<int> LocalSocket::release_fd()
|
|||
return fd;
|
||||
}
|
||||
|
||||
WrappedAKInputStream::WrappedAKInputStream(NonnullOwnPtr<InputStream> stream)
|
||||
: m_stream(move(stream))
|
||||
{
|
||||
}
|
||||
|
||||
ErrorOr<Bytes> WrappedAKInputStream::read(Bytes bytes)
|
||||
{
|
||||
auto bytes_read = m_stream->read(bytes);
|
||||
|
||||
if (m_stream->has_any_error())
|
||||
return Error::from_string_literal("Underlying InputStream indicated an error");
|
||||
|
||||
return bytes.slice(0, bytes_read);
|
||||
}
|
||||
|
||||
ErrorOr<size_t> WrappedAKInputStream::write(ReadonlyBytes)
|
||||
{
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
bool WrappedAKInputStream::is_eof() const
|
||||
{
|
||||
return m_stream->unreliable_eof();
|
||||
}
|
||||
|
||||
bool WrappedAKInputStream::is_open() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void WrappedAKInputStream::close()
|
||||
{
|
||||
}
|
||||
|
||||
WrappedAKOutputStream::WrappedAKOutputStream(NonnullOwnPtr<OutputStream> stream)
|
||||
: m_stream(move(stream))
|
||||
{
|
||||
}
|
||||
|
||||
ErrorOr<Bytes> WrappedAKOutputStream::read(Bytes)
|
||||
{
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
ErrorOr<size_t> WrappedAKOutputStream::write(ReadonlyBytes bytes)
|
||||
{
|
||||
auto bytes_written = m_stream->write(bytes);
|
||||
|
||||
if (m_stream->has_any_error())
|
||||
return Error::from_string_literal("Underlying OutputStream indicated an error");
|
||||
|
||||
return bytes_written;
|
||||
}
|
||||
|
||||
bool WrappedAKOutputStream::is_eof() const
|
||||
{
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
bool WrappedAKOutputStream::is_open() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void WrappedAKOutputStream::close()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue