Skip to content

Commit

Permalink
Merge pull request #1339 from villytiger/zlib-fix
Browse files Browse the repository at this point in the history
Fix reading from ZlibInputStream with exact buffer size
  • Loading branch information
s-ludwig committed Dec 2, 2015
2 parents 8c71e54 + 4b6b741 commit 18c692b
Showing 1 changed file with 19 additions and 1 deletion.
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

0 comments on commit 18c692b

Please sign in to comment.