summaryrefslogtreecommitdiff
path: root/lib/zlib.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-09-30 16:24:36 -0400
committerDaniel Bevenius <daniel.bevenius@gmail.com>2018-10-04 15:24:50 +0200
commitc0c58d5660aeea93c492877894f66dd55771be2e (patch)
treeb948b6ae21ecc5f042ce38e9644fd00151002dd8 /lib/zlib.js
parent1f7b6a6cc916a8bab942e579ed930e9e2d66c4e0 (diff)
downloadandroid-node-v8-c0c58d5660aeea93c492877894f66dd55771be2e.tar.gz
android-node-v8-c0c58d5660aeea93c492877894f66dd55771be2e.tar.bz2
android-node-v8-c0c58d5660aeea93c492877894f66dd55771be2e.zip
zlib: move, rename, document internal params() cb
Give the callback a more specific name, explain what it does and why it is necessary, and move it to a location much closer to its use site. PR-URL: https://github.com/nodejs/node/pull/23187 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/zlib.js')
-rw-r--r--lib/zlib.js28
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/zlib.js b/lib/zlib.js
index 87e8641767..6fb7696849 100644
--- a/lib/zlib.js
+++ b/lib/zlib.js
@@ -156,17 +156,6 @@ function zlibOnError(message, errno) {
self.emit('error', error);
}
-function flushCallback(level, strategy, callback) {
- if (!this._handle)
- assert(false, 'zlib binding closed');
- this._handle.params(level, strategy);
- if (!this._hadError) {
- this._level = level;
- this._strategy = strategy;
- if (callback) callback();
- }
-}
-
// 1. Returns false for undefined and NaN
// 2. Returns true for finite numbers
// 3. Throws ERR_INVALID_ARG_TYPE for non-numbers
@@ -352,13 +341,28 @@ Object.defineProperty(Zlib.prototype, 'bytesRead', {
}
});
+// This callback is used by `.params()` to wait until a full flush happened
+// before adjusting the parameters. In particular, the call to the native
+// `params()` function should not happen while a write is currently in progress
+// on the threadpool.
+function paramsAfterFlushCallback(level, strategy, callback) {
+ if (!this._handle)
+ assert(false, 'zlib binding closed');
+ this._handle.params(level, strategy);
+ if (!this._hadError) {
+ this._level = level;
+ this._strategy = strategy;
+ if (callback) callback();
+ }
+}
+
Zlib.prototype.params = function params(level, strategy, callback) {
checkRangesOrGetDefault(level, 'level', Z_MIN_LEVEL, Z_MAX_LEVEL);
checkRangesOrGetDefault(strategy, 'strategy', Z_DEFAULT_STRATEGY, Z_FIXED);
if (this._level !== level || this._strategy !== strategy) {
this.flush(Z_SYNC_FLUSH,
- flushCallback.bind(this, level, strategy, callback));
+ paramsAfterFlushCallback.bind(this, level, strategy, callback));
} else {
process.nextTick(callback);
}