1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:07:36 +00:00

GIODevice: Add a read_all() that returns a ByteBuffer with all we can read.

Use this to implement file opening in TextEditor.
This commit is contained in:
Andreas Kling 2019-03-18 14:38:30 +01:00
parent 8e3d0a23d5
commit 9ad076178a
6 changed files with 58 additions and 25 deletions

View file

@ -38,6 +38,7 @@ public:
byte* offset_pointer(int offset) { return m_data + offset; }
const byte* offset_pointer(int offset) const { return m_data + offset; }
void* end_pointer() { return m_data + m_size; }
const void* end_pointer() const { return m_data + m_size; }
// NOTE: trim() does not reallocate.
@ -109,6 +110,7 @@ public:
byte* offset_pointer(ssize_t offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
const byte* offset_pointer(ssize_t offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
void* end_pointer() { return m_impl ? m_impl->end_pointer() : nullptr; }
const void* end_pointer() const { return m_impl ? m_impl->end_pointer() : nullptr; }
// NOTE: trim() does not reallocate.
@ -137,6 +139,13 @@ public:
m_impl->grow(size);
}
void append(const void* data, int data_size)
{
int old_size = size();
grow(size() + data_size);
memcpy(pointer() + old_size, data, data_size);
}
private:
explicit ByteBuffer(RetainPtr<ByteBufferImpl>&& impl)
: m_impl(move(impl))