Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MemoryStream size changes #2251

Merged
merged 2 commits into from
Feb 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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