Skip to content

Commit

Permalink
Revert #57, close #196
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Nov 8, 2020
1 parent 505e36d commit 4e8ff8e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 5 additions & 16 deletions lib/deflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
**/

/**
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
Expand All @@ -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;
};

Expand All @@ -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) {
Expand Down
21 changes: 5 additions & 16 deletions lib/inflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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).
**/

/**
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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') {

Expand Down Expand Up @@ -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;
};

Expand All @@ -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) {
Expand Down

0 comments on commit 4e8ff8e

Please sign in to comment.