- high-level wrapper: make {in,de}flate.push(data, Z_SYNC_FLUSH) working

(will fix issue #34)
master
Tino Lange 2015-06-09 20:38:12 +02:00
rodzic ddaf928aec
commit a75010e2cc
2 zmienionych plików z 18 dodań i 2 usunięć

Wyświetl plik

@ -17,6 +17,7 @@ var Z_FINISH = 4;
var Z_OK = 0;
var Z_STREAM_END = 1;
var Z_SYNC_FLUSH = 2;
var Z_DEFAULT_COMPRESSION = -1;
@ -224,7 +225,7 @@ Deflate.prototype.push = function(data, mode) {
this.ended = true;
return false;
}
if (strm.avail_out === 0 || (strm.avail_in === 0 && _mode === Z_FINISH)) {
if (strm.avail_out === 0 || (strm.avail_in === 0 && (_mode === Z_FINISH || _mode === Z_SYNC_FLUSH))) {
if (this.options.to === 'string') {
this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));
} else {
@ -241,6 +242,13 @@ Deflate.prototype.push = function(data, mode) {
return status === Z_OK;
}
// callback interim results if Z_SYNC_FLUSH.
if (_mode === Z_SYNC_FLUSH) {
this.onEnd(Z_OK);
strm.avail_out = 0;
return true;
}
return true;
};

Wyświetl plik

@ -207,7 +207,7 @@ Inflate.prototype.push = function(data, mode) {
}
if (strm.next_out) {
if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && _mode === c.Z_FINISH)) {
if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && (_mode === c.Z_FINISH || _mode === c.Z_SYNC_FLUSH))) {
if (this.options.to === 'string') {
@ -233,6 +233,7 @@ Inflate.prototype.push = function(data, mode) {
if (status === c.Z_STREAM_END) {
_mode = c.Z_FINISH;
}
// Finalize on the last chunk.
if (_mode === c.Z_FINISH) {
status = zlib_inflate.inflateEnd(this.strm);
@ -241,6 +242,13 @@ Inflate.prototype.push = function(data, mode) {
return status === c.Z_OK;
}
// callback interim results if Z_SYNC_FLUSH.
if (_mode === c.Z_SYNC_FLUSH) {
this.onEnd(c.Z_OK);
strm.avail_out = 0;
return true;
}
return true;
};