summaryrefslogtreecommitdiff
path: root/lib/zlib.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/zlib.js')
-rw-r--r--lib/zlib.js34
1 files changed, 24 insertions, 10 deletions
diff --git a/lib/zlib.js b/lib/zlib.js
index 00be56dffc..c1cc0a2c54 100644
--- a/lib/zlib.js
+++ b/lib/zlib.js
@@ -182,37 +182,37 @@ class Zlib extends Transform {
this._finishFlushFlag = opts.finishFlush !== undefined ?
opts.finishFlush : constants.Z_FINISH;
- if (opts.chunkSize) {
+ if (opts.chunkSize !== undefined) {
if (opts.chunkSize < constants.Z_MIN_CHUNK) {
throw new RangeError('Invalid chunk size: ' + opts.chunkSize);
}
}
- if (opts.windowBits) {
+ if (opts.windowBits !== undefined) {
if (opts.windowBits < constants.Z_MIN_WINDOWBITS ||
opts.windowBits > constants.Z_MAX_WINDOWBITS) {
throw new RangeError('Invalid windowBits: ' + opts.windowBits);
}
}
- if (opts.level) {
+ if (opts.level !== undefined) {
if (opts.level < constants.Z_MIN_LEVEL ||
opts.level > constants.Z_MAX_LEVEL) {
throw new RangeError('Invalid compression level: ' + opts.level);
}
}
- if (opts.memLevel) {
+ if (opts.memLevel !== undefined) {
if (opts.memLevel < constants.Z_MIN_MEMLEVEL ||
opts.memLevel > constants.Z_MAX_MEMLEVEL) {
throw new RangeError('Invalid memLevel: ' + opts.memLevel);
}
}
- if (opts.strategy && isInvalidStrategy(opts.strategy))
+ if (opts.strategy !== undefined && isInvalidStrategy(opts.strategy))
throw new TypeError('Invalid strategy: ' + opts.strategy);
- if (opts.dictionary) {
+ if (opts.dictionary !== undefined) {
if (!ArrayBuffer.isView(opts.dictionary)) {
throw new TypeError(
'Invalid dictionary: it should be a Buffer, TypedArray, or DataView');
@@ -224,14 +224,28 @@ class Zlib extends Transform {
this._hadError = false;
var level = constants.Z_DEFAULT_COMPRESSION;
- if (typeof opts.level === 'number') level = opts.level;
+ if (Number.isFinite(opts.level)) {
+ level = opts.level;
+ }
var strategy = constants.Z_DEFAULT_STRATEGY;
- if (typeof opts.strategy === 'number') strategy = opts.strategy;
+ if (Number.isFinite(opts.strategy)) {
+ strategy = opts.strategy;
+ }
+
+ var windowBits = constants.Z_DEFAULT_WINDOWBITS;
+ if (Number.isFinite(opts.windowBits)) {
+ windowBits = opts.windowBits;
+ }
+
+ var memLevel = constants.Z_DEFAULT_MEMLEVEL;
+ if (Number.isFinite(opts.memLevel)) {
+ memLevel = opts.memLevel;
+ }
- this._handle.init(opts.windowBits || constants.Z_DEFAULT_WINDOWBITS,
+ this._handle.init(windowBits,
level,
- opts.memLevel || constants.Z_DEFAULT_MEMLEVEL,
+ memLevel,
strategy,
opts.dictionary);