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

Fix reading from ZlibInputStream with exact buffer size #1339

Merged
merged 1 commit into from
Dec 2, 2015
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
20 changes: 19 additions & 1 deletion source/vibe/stream/zlib.d
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class ZlibInputStream : InputStream {
dst = dst[len .. $];

if (!m_outbuffer.length && !m_finished) readChunk();
enforce(dst.length == 0 || !m_finished, "Reading past end of zlib stream.");
enforce(dst.length == 0 || m_outbuffer.length || !m_finished, "Reading past end of zlib stream.");
}
}

Expand Down Expand Up @@ -298,6 +298,24 @@ class ZlibInputStream : InputStream {
}
}

unittest {
import vibe.stream.memory;

auto data = new ubyte[5000];

auto mos = new MemoryOutputStream();
auto gos = new GzipOutputStream(mos);
gos.write(data);
gos.finalize();

auto ms = new MemoryStream(mos.data, false);
auto gis = new GzipInputStream(ms);

auto result = new ubyte[data.length];
gis.read(result);
assert(data == result);
}

private int zlibEnforce(int result)
{
switch (result) {
Expand Down