mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:57:35 +00:00
AK: Add DuplexMemoryStream::copy_into_contiguous_buffer.
This commit is contained in:
parent
b68a873067
commit
3a2658951b
1 changed files with 18 additions and 2 deletions
|
@ -225,7 +225,7 @@ public:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t read(Bytes bytes) override
|
size_t read_without_consuming(Bytes bytes) const
|
||||||
{
|
{
|
||||||
size_t nread = 0;
|
size_t nread = 0;
|
||||||
while (bytes.size() - nread > 0 && m_write_offset - m_read_offset - nread > 0) {
|
while (bytes.size() - nread > 0 && m_write_offset - m_read_offset - nread > 0) {
|
||||||
|
@ -234,8 +234,14 @@ public:
|
||||||
nread += chunk_bytes.copy_trimmed_to(bytes.slice(nread));
|
nread += chunk_bytes.copy_trimmed_to(bytes.slice(nread));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_read_offset += nread;
|
return nread;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t read(Bytes bytes) override
|
||||||
|
{
|
||||||
|
const auto nread = read_without_consuming(bytes);
|
||||||
|
|
||||||
|
m_read_offset += nread;
|
||||||
try_discard_chunks();
|
try_discard_chunks();
|
||||||
|
|
||||||
return nread;
|
return nread;
|
||||||
|
@ -272,6 +278,16 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ByteBuffer copy_into_contiguous_buffer() const
|
||||||
|
{
|
||||||
|
auto buffer = ByteBuffer::create_uninitialized(remaining());
|
||||||
|
|
||||||
|
const auto nread = read_without_consuming(buffer);
|
||||||
|
ASSERT(nread == buffer.size());
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
size_t roffset() const { return m_read_offset; }
|
size_t roffset() const { return m_read_offset; }
|
||||||
size_t woffset() const { return m_write_offset; }
|
size_t woffset() const { return m_write_offset; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue