summaryrefslogtreecommitdiff
path: root/AK/CircularBuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'AK/CircularBuffer.cpp')
-rw-r--r--AK/CircularBuffer.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/AK/CircularBuffer.cpp b/AK/CircularBuffer.cpp
index 0c6363c9fe..6ffe7ede66 100644
--- a/AK/CircularBuffer.cpp
+++ b/AK/CircularBuffer.cpp
@@ -6,6 +6,7 @@
#include <AK/CircularBuffer.h>
#include <AK/MemMem.h>
+#include <AK/Stream.h>
namespace AK {
@@ -189,4 +190,20 @@ ErrorOr<void> CircularBuffer::discard(size_t discarding_size)
return {};
}
+ErrorOr<size_t> CircularBuffer::fill_from_stream(Stream& stream)
+{
+ auto next_span = next_write_span();
+ if (next_span.size() == 0)
+ return 0;
+
+ auto bytes = TRY(stream.read_some(next_span));
+ m_used_space += bytes.size();
+
+ m_seekback_limit += bytes.size();
+ if (m_seekback_limit > capacity())
+ m_seekback_limit = capacity();
+
+ return bytes.size();
+}
+
}