Skip to content

Commit

Permalink
Merge pull request #2251 from vibe-d/memory_stream_size_change
Browse files Browse the repository at this point in the history
Support MemoryStream size changes
  • Loading branch information
s-ludwig authored Feb 2, 2019
2 parents 39367c9 + e4685e1 commit ee4921e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion stream/vibe/stream/memory.d
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ 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 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)]; }

Expand Down

0 comments on commit ee4921e

Please sign in to comment.