From 4e8ff8e74acca9211bb22c6c2f376f1625b175cd Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Mon, 9 Nov 2020 00:49:24 +0300 Subject: [PATCH] Revert #57, close #196 --- CHANGELOG.md | 1 + lib/deflate.js | 21 +++++---------------- lib/inflate.js | 21 +++++---------------- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4446f83..385db56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed binary strings and `Array` support. - Removed fallbacks for unsupported TypedArray methods (`.set()`, `.subarray()`). - Removed support of `Inflate` & `Deflate` instance create without `new`. +- Removed `Z_SYNC_FLUSH` related code from wrappers (buggy and no tests). - Switched to es6. Legacy es5 builds available in `/dist`. - Structure of `/dist` folder changed. - Upgraded build tools to modern ones. diff --git a/lib/deflate.js b/lib/deflate.js index 97aad88..2ba7869 100644 --- a/lib/deflate.js +++ b/lib/deflate.js @@ -14,7 +14,7 @@ const toString = Object.prototype.toString; const { Z_NO_FLUSH, Z_FINISH, - Z_OK, Z_STREAM_END, Z_SYNC_FLUSH, + Z_OK, Z_STREAM_END, Z_DEFAULT_COMPRESSION, Z_DEFAULT_STRATEGY, Z_DEFLATED @@ -42,9 +42,7 @@ const { * * Compressed result, generated by default [[Deflate#onData]] * and [[Deflate#onEnd]] handlers. Filled after you push last chunk - * (call [[Deflate#push]] with `Z_FINISH` / `true` param) or if you - * push a chunk with explicit flush (call [[Deflate#push]] with - * `Z_SYNC_FLUSH` param). + * (call [[Deflate#push]] with `Z_FINISH` / `true` param). **/ /** @@ -187,8 +185,7 @@ function Deflate(options) { * Sends input data to deflate pipe, generating [[Deflate#onData]] calls with * new compressed chunks. Returns `true` on success. The last data block must have * mode Z_FINISH (or `true`). That will flush internal pending buffers and call - * [[Deflate#onEnd]]. For interim explicit flushes (without ending the stream) you - * can use mode Z_SYNC_FLUSH, keeping the compression context. + * [[Deflate#onEnd]]. * * On fail call [[Deflate#onEnd]] with error code and return false. * @@ -238,7 +235,7 @@ Deflate.prototype.push = function (data, mode) { this.ended = true; return false; } - if (strm.avail_out === 0 || (strm.avail_in === 0 && (_mode === Z_FINISH || _mode === Z_SYNC_FLUSH))) { + if (strm.avail_out === 0 || (strm.avail_in === 0 && _mode === Z_FINISH)) { this.onData(strm.output.length === strm.next_out ? strm.output : strm.output.subarray(0, strm.next_out)); } } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END); @@ -251,13 +248,6 @@ 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; }; @@ -280,8 +270,7 @@ Deflate.prototype.onData = function (chunk) { * other if not. * * Called once after you tell deflate that the input stream is - * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH) - * or if an error happened. By default - join collected chunks, + * complete (Z_FINISH). By default - join collected chunks, * free memory and fill `results` / `err` properties. **/ Deflate.prototype.onEnd = function (status) { diff --git a/lib/inflate.js b/lib/inflate.js index 2a5cb88..0489a09 100644 --- a/lib/inflate.js +++ b/lib/inflate.js @@ -14,7 +14,7 @@ const toString = Object.prototype.toString; /* ===========================================================================*/ const { - Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, + Z_NO_FLUSH, Z_FINISH, Z_OK, Z_STREAM_END, Z_NEED_DICT, Z_BUF_ERROR } = require('./zlib/constants'); @@ -40,9 +40,7 @@ const { * * Uncompressed result, generated by default [[Inflate#onData]] * and [[Inflate#onEnd]] handlers. Filled after you push last chunk - * (call [[Inflate#push]] with `Z_FINISH` / `true` param) or if you - * push a chunk with explicit flush (call [[Inflate#push]] with - * `Z_SYNC_FLUSH` param). + * (call [[Inflate#push]] with `Z_FINISH` / `true` param). **/ /** @@ -179,8 +177,7 @@ function Inflate(options) { * Sends input data to inflate pipe, generating [[Inflate#onData]] calls with * new output chunks. Returns `true` on success. The last data block must have * mode Z_FINISH (or `true`). That will flush internal pending buffers and call - * [[Inflate#onEnd]]. For interim explicit flushes (without ending the stream) you - * can use mode Z_SYNC_FLUSH, keeping the decompression context. + * [[Inflate#onEnd]]. * * On fail call [[Inflate#onEnd]] with error code and return false. * @@ -244,7 +241,7 @@ Inflate.prototype.push = function (data, mode) { } if (strm.next_out) { - if (strm.avail_out === 0 || status === Z_STREAM_END || (strm.avail_in === 0 && (_mode === Z_FINISH || _mode === Z_SYNC_FLUSH))) { + if (strm.avail_out === 0 || status === Z_STREAM_END || (strm.avail_in === 0 && _mode === Z_FINISH)) { if (this.options.to === 'string') { @@ -291,13 +288,6 @@ Inflate.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; }; @@ -321,8 +311,7 @@ Inflate.prototype.onData = function (chunk) { * other if not. * * Called either after you tell inflate that the input stream is - * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH) - * or if an error happened. By default - join collected chunks, + * complete (Z_FINISH). By default - join collected chunks, * free memory and fill `results` / `err` properties. **/ Inflate.prototype.onEnd = function (status) {