From 9ff56fb8ca0dde95b506f589b539eb310a265277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sat, 12 Jan 2019 14:40:45 +0100 Subject: [PATCH 1/2] Fix assertion condition to allow MemoryStream to grow. --- stream/vibe/stream/memory.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream/vibe/stream/memory.d b/stream/vibe/stream/memory.d index b6b9c30e89..384091fd19 100644 --- a/stream/vibe/stream/memory.d +++ b/stream/vibe/stream/memory.d @@ -134,7 +134,7 @@ final class MemoryStream : RandomAccessStream { @property bool readable() const nothrow { return true; } @property bool writable() const nothrow { return m_writable; } - void seek(ulong offset) { assert(offset <= m_size); m_ptr = cast(size_t)offset; } + void seek(ulong offset) { assert(offset <= m_data.length); m_ptr = cast(size_t)offset; } ulong tell() nothrow { return m_ptr; } const(ubyte)[] peek() { return m_data[m_ptr .. min(m_size, m_ptr+m_peekWindow)]; } From e4685e1642dcd840d8e096eebc5f828e0ae5c280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sat, 12 Jan 2019 14:41:56 +0100 Subject: [PATCH 2/2] Add MemoryStream.truncate. --- stream/vibe/stream/memory.d | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stream/vibe/stream/memory.d b/stream/vibe/stream/memory.d index 384091fd19..6a55fccfbb 100644 --- a/stream/vibe/stream/memory.d +++ b/stream/vibe/stream/memory.d @@ -134,6 +134,12 @@ final class MemoryStream : RandomAccessStream { @property bool readable() const nothrow { return true; } @property bool writable() const nothrow { return m_writable; } + void truncate(ulong size) + { + enforce(size < m_data.length, "Size limit of memory stream reached."); + m_size = cast(size_t)size; + } + void seek(ulong offset) { assert(offset <= m_data.length); m_ptr = cast(size_t)offset; } ulong tell() nothrow { return m_ptr; } const(ubyte)[] peek() { return m_data[m_ptr .. min(m_size, m_ptr+m_peekWindow)]; }