Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/hx/zip/zlib/ZLibCompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ hx::zip::Result hx::zip::zlib::ZLibCompress::execute(cpp::marshal::View<uint8_t>
hx::Throw(HX_CSTRING("ZLib Error"));
}

// Per-call counts, as haxe.zip expects; total_in/total_out accumulate across calls.
return
Result(
error == Z_STREAM_END,
static_cast<int>(handle->total_in),
static_cast<int>(handle->total_out));
static_cast<int>(src.length - handle->avail_in),
static_cast<int>(dst.length - handle->avail_out));
}

void hx::zip::zlib::ZLibCompress::setFlushMode(Flush mode)
Expand Down
5 changes: 3 additions & 2 deletions src/hx/zip/zlib/ZLibUncompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ hx::zip::Result hx::zip::zlib::ZLibUncompress::execute(cpp::marshal::View<uint8_
hx::Throw(HX_CSTRING("ZLib Error"));
}

// Per-call counts, as haxe.zip expects; total_in/total_out accumulate across calls.
return
Result(
error == Z_STREAM_END,
static_cast<int>(handle->total_in),
static_cast<int>(handle->total_out));
static_cast<int>(src.length - handle->avail_in),
static_cast<int>(dst.length - handle->avail_out));
}

void hx::zip::zlib::ZLibUncompress::setFlushMode(Flush mode)
Expand Down
31 changes: 31 additions & 0 deletions test/std/Test.hx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,37 @@ class Test extends utest.Test
Assert.equals(0, decompressed.compare(bytes), "Compress/Uncompress mismatch");
}

function testCompressMultipleBuffers()
{
log("Test compress/uncompress across multiple buffers");
// Larger than the 64K default buffer so execute is called more than once.
final bytes = haxe.io.Bytes.alloc(300000);
for(i in 0...bytes.length)
bytes.set(i, (i * 7 + (i >> 9)) & 0xff);

final compressed = Compress.run(bytes, 9);
final decompressed = Uncompress.run(compressed);
Assert.equals(bytes.length, decompressed.length, "Uncompress length");
Assert.equals(0, decompressed.compare(bytes), "Uncompress mismatch");

final uncompress = new Uncompress();
final chunk = haxe.io.Bytes.alloc(4096);
final output = new haxe.io.BytesBuffer();
var pos = 0;
while(true)
{
final r = uncompress.execute(compressed, pos, chunk, 0);
Assert.isTrue(r.write <= chunk.length, "Per-call write exceeds buffer");
output.addBytes(chunk, 0, r.write);
pos += r.read;
if (r.done)
break;
}
uncompress.close();
Assert.equals(compressed.length, pos, "Per-call reads sum to input");
Assert.equals(0, output.getBytes().compare(bytes), "Chunked uncompress mismatch");
}


function testRegexp()
{
Expand Down