diff --git a/lib/inflate.js b/lib/inflate.js index f754336..8d7a987 100644 --- a/lib/inflate.js +++ b/lib/inflate.js @@ -177,6 +177,8 @@ Inflate.prototype.push = function(data, mode) { var chunkSize = this.options.chunkSize; var status, _mode; var next_out_utf8, tail, utf8str; + // allow Z_BUF_ERROR on next inflate call + var allowBufError = 0; if (this.ended) { return false; } _mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH); @@ -203,6 +205,11 @@ Inflate.prototype.push = function(data, mode) { status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */ + if (status === c.Z_BUF_ERROR && allowBufError === 1) { + status = c.Z_OK; + allowBufError = 0; + } + if (status !== c.Z_STREAM_END && status !== c.Z_OK) { this.onEnd(status); this.ended = true; @@ -231,7 +238,11 @@ Inflate.prototype.push = function(data, mode) { } } } - } while ((strm.avail_in > 0) && status !== c.Z_STREAM_END); + // we need to check internal inflate buffers and state but inflate can return Z_BUF_ERROR if no output + if (strm.avail_in === 0 && strm.avail_out === 0) { + allowBufError = 1; + } + } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== c.Z_STREAM_END); if (status === c.Z_STREAM_END) { _mode = c.Z_FINISH; diff --git a/test/fixtures/samples_deflated_raw/KW_Rocketry_1.compressed b/test/fixtures/samples_deflated_raw/KW_Rocketry_1.compressed new file mode 100644 index 0000000..5c998e3 Binary files /dev/null and b/test/fixtures/samples_deflated_raw/KW_Rocketry_1.compressed differ diff --git a/test/fixtures/samples_deflated_raw/shapefile.compressed b/test/fixtures/samples_deflated_raw/shapefile.compressed new file mode 100644 index 0000000..49e4ff3 Binary files /dev/null and b/test/fixtures/samples_deflated_raw/shapefile.compressed differ