diff --git a/doc/api/zlib.md b/doc/api/zlib.md index 3728015fc4..bddeead132 100644 --- a/doc/api/zlib.md +++ b/doc/api/zlib.md @@ -123,7 +123,9 @@ method that is used to compressed the last chunk of input data: // This is a truncated version of the buffer from the above examples const buffer = Buffer.from('eJzT0yMA', 'base64'); -zlib.unzip(buffer, { finishFlush: zlib.Z_SYNC_FLUSH }, (err, buffer) => { +zlib.unzip(buffer, + {finishFlush: zlib.constants.Z_SYNC_FLUSH}, + (err, buffer) => { if (!err) { console.log(buffer.toString()); } else { @@ -221,65 +223,56 @@ added: v0.5.8 -All of the constants defined in `zlib.h` are also defined on `require('zlib')`. -In the normal course of operations, it will not be necessary to use these -constants. They are documented so that their presence is not surprising. This -section is taken almost directly from the [zlib documentation][]. See - for more details. +All of the constants defined in `zlib.h` are also defined on +`require('zlib').constants`. In the normal course of operations, it will not be +necessary to use these constants. They are documented so that their presence is +not surprising. This section is taken almost directly from the +[zlib documentation][]. See for more +details. + +*Note*: Previously, the constants were available directly from +`require('zlib')`, for instance `zlib.Z_NO_FLUSH`. Accessing the constants +directly from the module is currently still possible but should be considered +deprecated. Allowed flush values. -* `zlib.Z_NO_FLUSH` -* `zlib.Z_PARTIAL_FLUSH` -* `zlib.Z_SYNC_FLUSH` -* `zlib.Z_FULL_FLUSH` -* `zlib.Z_FINISH` -* `zlib.Z_BLOCK` -* `zlib.Z_TREES` +* `zlib.constants.Z_NO_FLUSH` +* `zlib.constants.Z_PARTIAL_FLUSH` +* `zlib.constants.Z_SYNC_FLUSH` +* `zlib.constants.Z_FULL_FLUSH` +* `zlib.constants.Z_FINISH` +* `zlib.constants.Z_BLOCK` +* `zlib.constants.Z_TREES` Return codes for the compression/decompression functions. Negative values are errors, positive values are used for special but normal events. -* `zlib.Z_OK` -* `zlib.Z_STREAM_END` -* `zlib.Z_NEED_DICT` -* `zlib.Z_ERRNO` -* `zlib.Z_STREAM_ERROR` -* `zlib.Z_DATA_ERROR` -* `zlib.Z_MEM_ERROR` -* `zlib.Z_BUF_ERROR` -* `zlib.Z_VERSION_ERROR` +* `zlib.constants.Z_OK` +* `zlib.constants.Z_STREAM_END` +* `zlib.constants.Z_NEED_DICT` +* `zlib.constants.Z_ERRNO` +* `zlib.constants.Z_STREAM_ERROR` +* `zlib.constants.Z_DATA_ERROR` +* `zlib.constants.Z_MEM_ERROR` +* `zlib.constants.Z_BUF_ERROR` +* `zlib.constants.Z_VERSION_ERROR` Compression levels. -* `zlib.Z_NO_COMPRESSION` -* `zlib.Z_BEST_SPEED` -* `zlib.Z_BEST_COMPRESSION` -* `zlib.Z_DEFAULT_COMPRESSION` +* `zlib.constants.Z_NO_COMPRESSION` +* `zlib.constants.Z_BEST_SPEED` +* `zlib.constants.Z_BEST_COMPRESSION` +* `zlib.constants.Z_DEFAULT_COMPRESSION` Compression strategy. -* `zlib.Z_FILTERED` -* `zlib.Z_HUFFMAN_ONLY` -* `zlib.Z_RLE` -* `zlib.Z_FIXED` -* `zlib.Z_DEFAULT_STRATEGY` - -Possible values of the data_type field. - -* `zlib.Z_BINARY` -* `zlib.Z_TEXT` -* `zlib.Z_ASCII` -* `zlib.Z_UNKNOWN` - -The deflate compression method (the only one supported in this version). - -* `zlib.Z_DEFLATED` - -For initializing zalloc, zfree, opaque. - -* `zlib.Z_NULL` +* `zlib.constants.Z_FILTERED` +* `zlib.constants.Z_HUFFMAN_ONLY` +* `zlib.constants.Z_RLE` +* `zlib.constants.Z_FIXED` +* `zlib.constants.Z_DEFAULT_STRATEGY` ## Class Options -`kind` defaults to `zlib.Z_FULL_FLUSH`. +`kind` defaults to `zlib.constants.Z_FULL_FLUSH`. Flush pending data. Don't call this frivolously, premature flushes negatively impact the effectiveness of the compression algorithm. @@ -391,6 +384,10 @@ Only applicable to deflate algorithm. added: v0.7.0 --> +## zlib.constants + +Provides an object enumerating Zlib-related [constants][]. + Reset the compressor/decompressor to factory defaults. Only applicable to the inflate and deflate algorithms. @@ -545,3 +542,4 @@ Decompress a Buffer or string with Unzip. [Unzip]: #zlib_class_zlib_unzip [`.flush()`]: #zlib_zlib_flush_kind_callback [Buffer]: buffer.html +[constants]: #constants_constants diff --git a/lib/zlib.js b/lib/zlib.js index ffb7ba6c69..42dd561623 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -9,49 +9,35 @@ const kMaxLength = require('buffer').kMaxLength; const kRangeErrorMessage = 'Cannot create final Buffer. It would be larger ' + 'than 0x' + kMaxLength.toString(16) + ' bytes'; -// zlib doesn't provide these, so kludge them in following the same -// const naming scheme zlib uses. -binding.Z_MIN_WINDOWBITS = 8; -binding.Z_MAX_WINDOWBITS = 15; -binding.Z_DEFAULT_WINDOWBITS = 15; - -// fewer than 64 bytes per chunk is stupid. -// technically it could work with as few as 8, but even 64 bytes -// is absurdly low. Usually a MB or more is best. -binding.Z_MIN_CHUNK = 64; -binding.Z_MAX_CHUNK = Infinity; -binding.Z_DEFAULT_CHUNK = (16 * 1024); - -binding.Z_MIN_MEMLEVEL = 1; -binding.Z_MAX_MEMLEVEL = 9; -binding.Z_DEFAULT_MEMLEVEL = 8; - -binding.Z_MIN_LEVEL = -1; -binding.Z_MAX_LEVEL = 9; -binding.Z_DEFAULT_LEVEL = binding.Z_DEFAULT_COMPRESSION; +const constants = process.binding('constants').zlib; +// These should be considered deprecated // expose all the zlib constants -const bkeys = Object.keys(binding); +const bkeys = Object.keys(constants); for (var bk = 0; bk < bkeys.length; bk++) { var bkey = bkeys[bk]; - if (bkey.match(/^Z/)) { - Object.defineProperty(exports, bkey, { - enumerable: true, value: binding[bkey], writable: false - }); - } + Object.defineProperty(exports, bkey, { + enumerable: true, value: constants[bkey], writable: false + }); } +Object.defineProperty(exports, 'constants', { + configurable: false, + enumerable: true, + value: constants +}); + // translation table for return codes. const codes = { - Z_OK: binding.Z_OK, - Z_STREAM_END: binding.Z_STREAM_END, - Z_NEED_DICT: binding.Z_NEED_DICT, - Z_ERRNO: binding.Z_ERRNO, - Z_STREAM_ERROR: binding.Z_STREAM_ERROR, - Z_DATA_ERROR: binding.Z_DATA_ERROR, - Z_MEM_ERROR: binding.Z_MEM_ERROR, - Z_BUF_ERROR: binding.Z_BUF_ERROR, - Z_VERSION_ERROR: binding.Z_VERSION_ERROR + Z_OK: constants.Z_OK, + Z_STREAM_END: constants.Z_STREAM_END, + Z_NEED_DICT: constants.Z_NEED_DICT, + Z_ERRNO: constants.Z_ERRNO, + Z_STREAM_ERROR: constants.Z_STREAM_ERROR, + Z_DATA_ERROR: constants.Z_DATA_ERROR, + Z_MEM_ERROR: constants.Z_MEM_ERROR, + Z_BUF_ERROR: constants.Z_BUF_ERROR, + Z_VERSION_ERROR: constants.Z_VERSION_ERROR }; const ckeys = Object.keys(codes); @@ -243,52 +229,52 @@ function zlibBufferSync(engine, buffer) { // minimal 2-byte header function Deflate(opts) { if (!(this instanceof Deflate)) return new Deflate(opts); - Zlib.call(this, opts, binding.DEFLATE); + Zlib.call(this, opts, constants.DEFLATE); } function Inflate(opts) { if (!(this instanceof Inflate)) return new Inflate(opts); - Zlib.call(this, opts, binding.INFLATE); + Zlib.call(this, opts, constants.INFLATE); } // gzip - bigger header, same deflate compression function Gzip(opts) { if (!(this instanceof Gzip)) return new Gzip(opts); - Zlib.call(this, opts, binding.GZIP); + Zlib.call(this, opts, constants.GZIP); } function Gunzip(opts) { if (!(this instanceof Gunzip)) return new Gunzip(opts); - Zlib.call(this, opts, binding.GUNZIP); + Zlib.call(this, opts, constants.GUNZIP); } // raw - no header function DeflateRaw(opts) { if (!(this instanceof DeflateRaw)) return new DeflateRaw(opts); - Zlib.call(this, opts, binding.DEFLATERAW); + Zlib.call(this, opts, constants.DEFLATERAW); } function InflateRaw(opts) { if (!(this instanceof InflateRaw)) return new InflateRaw(opts); - Zlib.call(this, opts, binding.INFLATERAW); + Zlib.call(this, opts, constants.INFLATERAW); } // auto-detect header. function Unzip(opts) { if (!(this instanceof Unzip)) return new Unzip(opts); - Zlib.call(this, opts, binding.UNZIP); + Zlib.call(this, opts, constants.UNZIP); } function isValidFlushFlag(flag) { - return flag === binding.Z_NO_FLUSH || - flag === binding.Z_PARTIAL_FLUSH || - flag === binding.Z_SYNC_FLUSH || - flag === binding.Z_FULL_FLUSH || - flag === binding.Z_FINISH || - flag === binding.Z_BLOCK; + return flag === constants.Z_NO_FLUSH || + flag === constants.Z_PARTIAL_FLUSH || + flag === constants.Z_SYNC_FLUSH || + flag === constants.Z_FULL_FLUSH || + flag === constants.Z_FINISH || + flag === constants.Z_BLOCK; } // the Zlib class they all inherit from @@ -298,7 +284,7 @@ function isValidFlushFlag(flag) { function Zlib(opts, mode) { this._opts = opts = opts || {}; - this._chunkSize = opts.chunkSize || exports.Z_DEFAULT_CHUNK; + this._chunkSize = opts.chunkSize || constants.Z_DEFAULT_CHUNK; Transform.call(this, opts); @@ -309,44 +295,44 @@ function Zlib(opts, mode) { throw new Error('Invalid flush flag: ' + opts.finishFlush); } - this._flushFlag = opts.flush || binding.Z_NO_FLUSH; + this._flushFlag = opts.flush || constants.Z_NO_FLUSH; this._finishFlushFlag = typeof opts.finishFlush !== 'undefined' ? - opts.finishFlush : binding.Z_FINISH; + opts.finishFlush : constants.Z_FINISH; if (opts.chunkSize) { - if (opts.chunkSize < exports.Z_MIN_CHUNK || - opts.chunkSize > exports.Z_MAX_CHUNK) { + if (opts.chunkSize < constants.Z_MIN_CHUNK || + opts.chunkSize > constants.Z_MAX_CHUNK) { throw new Error('Invalid chunk size: ' + opts.chunkSize); } } if (opts.windowBits) { - if (opts.windowBits < exports.Z_MIN_WINDOWBITS || - opts.windowBits > exports.Z_MAX_WINDOWBITS) { + if (opts.windowBits < constants.Z_MIN_WINDOWBITS || + opts.windowBits > constants.Z_MAX_WINDOWBITS) { throw new Error('Invalid windowBits: ' + opts.windowBits); } } if (opts.level) { - if (opts.level < exports.Z_MIN_LEVEL || - opts.level > exports.Z_MAX_LEVEL) { + if (opts.level < constants.Z_MIN_LEVEL || + opts.level > constants.Z_MAX_LEVEL) { throw new Error('Invalid compression level: ' + opts.level); } } if (opts.memLevel) { - if (opts.memLevel < exports.Z_MIN_MEMLEVEL || - opts.memLevel > exports.Z_MAX_MEMLEVEL) { + if (opts.memLevel < constants.Z_MIN_MEMLEVEL || + opts.memLevel > constants.Z_MAX_MEMLEVEL) { throw new Error('Invalid memLevel: ' + opts.memLevel); } } if (opts.strategy) { - if (opts.strategy != exports.Z_FILTERED && - opts.strategy != exports.Z_HUFFMAN_ONLY && - opts.strategy != exports.Z_RLE && - opts.strategy != exports.Z_FIXED && - opts.strategy != exports.Z_DEFAULT_STRATEGY) { + if (opts.strategy != constants.Z_FILTERED && + opts.strategy != constants.Z_HUFFMAN_ONLY && + opts.strategy != constants.Z_RLE && + opts.strategy != constants.Z_FIXED && + opts.strategy != constants.Z_DEFAULT_STRATEGY) { throw new Error('Invalid strategy: ' + opts.strategy); } } @@ -373,15 +359,15 @@ function Zlib(opts, mode) { self.emit('error', error); }; - var level = exports.Z_DEFAULT_COMPRESSION; + var level = constants.Z_DEFAULT_COMPRESSION; if (typeof opts.level === 'number') level = opts.level; - var strategy = exports.Z_DEFAULT_STRATEGY; + var strategy = constants.Z_DEFAULT_STRATEGY; if (typeof opts.strategy === 'number') strategy = opts.strategy; - this._handle.init(opts.windowBits || exports.Z_DEFAULT_WINDOWBITS, + this._handle.init(opts.windowBits || constants.Z_DEFAULT_WINDOWBITS, level, - opts.memLevel || exports.Z_DEFAULT_MEMLEVEL, + opts.memLevel || constants.Z_DEFAULT_MEMLEVEL, strategy, opts.dictionary); @@ -402,21 +388,21 @@ function Zlib(opts, mode) { util.inherits(Zlib, Transform); Zlib.prototype.params = function(level, strategy, callback) { - if (level < exports.Z_MIN_LEVEL || - level > exports.Z_MAX_LEVEL) { + if (level < constants.Z_MIN_LEVEL || + level > constants.Z_MAX_LEVEL) { throw new RangeError('Invalid compression level: ' + level); } - if (strategy != exports.Z_FILTERED && - strategy != exports.Z_HUFFMAN_ONLY && - strategy != exports.Z_RLE && - strategy != exports.Z_FIXED && - strategy != exports.Z_DEFAULT_STRATEGY) { + if (strategy != constants.Z_FILTERED && + strategy != constants.Z_HUFFMAN_ONLY && + strategy != constants.Z_RLE && + strategy != constants.Z_FIXED && + strategy != constants.Z_DEFAULT_STRATEGY) { throw new TypeError('Invalid strategy: ' + strategy); } if (this._level !== level || this._strategy !== strategy) { var self = this; - this.flush(binding.Z_SYNC_FLUSH, function() { + this.flush(constants.Z_SYNC_FLUSH, function() { assert(self._handle, 'zlib binding closed'); self._handle.params(level, strategy); if (!self._hadError) { @@ -446,7 +432,7 @@ Zlib.prototype.flush = function(kind, callback) { if (typeof kind === 'function' || (kind === undefined && !callback)) { callback = kind; - kind = binding.Z_FULL_FLUSH; + kind = constants.Z_FULL_FLUSH; } if (ws.ended) { @@ -510,7 +496,7 @@ Zlib.prototype._transform = function(chunk, encoding, cb) { // once we've flushed the last of the queue, stop flushing and // go back to the normal behavior. if (chunk.length >= ws.length) { - this._flushFlag = this._opts.flush || binding.Z_NO_FLUSH; + this._flushFlag = this._opts.flush || constants.Z_NO_FLUSH; } } diff --git a/src/node_constants.cc b/src/node_constants.cc index 2e6be8df37..8aa65ee7e2 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -3,6 +3,7 @@ #include "env-inl.h" #include "uv.h" +#include "zlib.h" #include #if !defined(_MSC_VER) @@ -12,6 +13,7 @@ #include #include #include +#include #if HAVE_OPENSSL # include @@ -1142,12 +1144,92 @@ void DefineCryptoConstants(Local target) { #endif } +void DefineZlibConstants(Local target) { + NODE_DEFINE_CONSTANT(target, Z_NO_FLUSH); + NODE_DEFINE_CONSTANT(target, Z_PARTIAL_FLUSH); + NODE_DEFINE_CONSTANT(target, Z_SYNC_FLUSH); + NODE_DEFINE_CONSTANT(target, Z_FULL_FLUSH); + NODE_DEFINE_CONSTANT(target, Z_FINISH); + NODE_DEFINE_CONSTANT(target, Z_BLOCK); + + // return/error codes + NODE_DEFINE_CONSTANT(target, Z_OK); + NODE_DEFINE_CONSTANT(target, Z_STREAM_END); + NODE_DEFINE_CONSTANT(target, Z_NEED_DICT); + NODE_DEFINE_CONSTANT(target, Z_ERRNO); + NODE_DEFINE_CONSTANT(target, Z_STREAM_ERROR); + NODE_DEFINE_CONSTANT(target, Z_DATA_ERROR); + NODE_DEFINE_CONSTANT(target, Z_MEM_ERROR); + NODE_DEFINE_CONSTANT(target, Z_BUF_ERROR); + NODE_DEFINE_CONSTANT(target, Z_VERSION_ERROR); + + NODE_DEFINE_CONSTANT(target, Z_NO_COMPRESSION); + NODE_DEFINE_CONSTANT(target, Z_BEST_SPEED); + NODE_DEFINE_CONSTANT(target, Z_BEST_COMPRESSION); + NODE_DEFINE_CONSTANT(target, Z_DEFAULT_COMPRESSION); + NODE_DEFINE_CONSTANT(target, Z_FILTERED); + NODE_DEFINE_CONSTANT(target, Z_HUFFMAN_ONLY); + NODE_DEFINE_CONSTANT(target, Z_RLE); + NODE_DEFINE_CONSTANT(target, Z_FIXED); + NODE_DEFINE_CONSTANT(target, Z_DEFAULT_STRATEGY); + NODE_DEFINE_CONSTANT(target, ZLIB_VERNUM); + + enum node_zlib_mode { + NONE, + DEFLATE, + INFLATE, + GZIP, + GUNZIP, + DEFLATERAW, + INFLATERAW, + UNZIP + }; + + NODE_DEFINE_CONSTANT(target, DEFLATE); + NODE_DEFINE_CONSTANT(target, INFLATE); + NODE_DEFINE_CONSTANT(target, GZIP); + NODE_DEFINE_CONSTANT(target, GUNZIP); + NODE_DEFINE_CONSTANT(target, DEFLATERAW); + NODE_DEFINE_CONSTANT(target, INFLATERAW); + NODE_DEFINE_CONSTANT(target, UNZIP); + +#define Z_MIN_WINDOWBITS 8 +#define Z_MAX_WINDOWBITS 15 +#define Z_DEFAULT_WINDOWBITS 15 +// Fewer than 64 bytes per chunk is not recommended. +// Technically it could work with as few as 8, but even 64 bytes +// is low. Usually a MB or more is best. +#define Z_MIN_CHUNK 64 +#define Z_MAX_CHUNK std::numeric_limits::infinity() +#define Z_DEFAULT_CHUNK (16 * 1024) +#define Z_MIN_MEMLEVEL 1 +#define Z_MAX_MEMLEVEL 9 +#define Z_DEFAULT_MEMLEVEL 8 +#define Z_MIN_LEVEL -1 +#define Z_MAX_LEVEL 9 +#define Z_DEFAULT_LEVEL Z_DEFAULT_COMPRESSION + + NODE_DEFINE_CONSTANT(target, Z_MIN_WINDOWBITS); + NODE_DEFINE_CONSTANT(target, Z_MAX_WINDOWBITS); + NODE_DEFINE_CONSTANT(target, Z_DEFAULT_WINDOWBITS); + NODE_DEFINE_CONSTANT(target, Z_MIN_CHUNK); + NODE_DEFINE_CONSTANT(target, Z_MAX_CHUNK); + NODE_DEFINE_CONSTANT(target, Z_DEFAULT_CHUNK); + NODE_DEFINE_CONSTANT(target, Z_MIN_MEMLEVEL); + NODE_DEFINE_CONSTANT(target, Z_MAX_MEMLEVEL); + NODE_DEFINE_CONSTANT(target, Z_DEFAULT_MEMLEVEL); + NODE_DEFINE_CONSTANT(target, Z_MIN_LEVEL); + NODE_DEFINE_CONSTANT(target, Z_MAX_LEVEL); + NODE_DEFINE_CONSTANT(target, Z_DEFAULT_LEVEL); +} + void DefineConstants(v8::Isolate* isolate, Local target) { Local os_constants = Object::New(isolate); Local err_constants = Object::New(isolate); Local sig_constants = Object::New(isolate); Local fs_constants = Object::New(isolate); Local crypto_constants = Object::New(isolate); + Local zlib_constants = Object::New(isolate); DefineErrnoConstants(err_constants); DefineWindowsErrorConstants(err_constants); @@ -1156,12 +1238,14 @@ void DefineConstants(v8::Isolate* isolate, Local target) { DefineSystemConstants(fs_constants); DefineOpenSSLConstants(crypto_constants); DefineCryptoConstants(crypto_constants); + DefineZlibConstants(zlib_constants); os_constants->Set(OneByteString(isolate, "errno"), err_constants); os_constants->Set(OneByteString(isolate, "signals"), sig_constants); target->Set(OneByteString(isolate, "os"), os_constants); target->Set(OneByteString(isolate, "fs"), fs_constants); target->Set(OneByteString(isolate, "crypto"), crypto_constants); + target->Set(OneByteString(isolate, "zlib"), zlib_constants); } } // namespace node diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 4de9d7cdc2..a6fbf06389 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -666,44 +666,6 @@ void InitZlib(Local target, z->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Zlib")); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Zlib"), z->GetFunction()); - // valid flush values. - NODE_DEFINE_CONSTANT(target, Z_NO_FLUSH); - NODE_DEFINE_CONSTANT(target, Z_PARTIAL_FLUSH); - NODE_DEFINE_CONSTANT(target, Z_SYNC_FLUSH); - NODE_DEFINE_CONSTANT(target, Z_FULL_FLUSH); - NODE_DEFINE_CONSTANT(target, Z_FINISH); - NODE_DEFINE_CONSTANT(target, Z_BLOCK); - - // return/error codes - NODE_DEFINE_CONSTANT(target, Z_OK); - NODE_DEFINE_CONSTANT(target, Z_STREAM_END); - NODE_DEFINE_CONSTANT(target, Z_NEED_DICT); - NODE_DEFINE_CONSTANT(target, Z_ERRNO); - NODE_DEFINE_CONSTANT(target, Z_STREAM_ERROR); - NODE_DEFINE_CONSTANT(target, Z_DATA_ERROR); - NODE_DEFINE_CONSTANT(target, Z_MEM_ERROR); - NODE_DEFINE_CONSTANT(target, Z_BUF_ERROR); - NODE_DEFINE_CONSTANT(target, Z_VERSION_ERROR); - - NODE_DEFINE_CONSTANT(target, Z_NO_COMPRESSION); - NODE_DEFINE_CONSTANT(target, Z_BEST_SPEED); - NODE_DEFINE_CONSTANT(target, Z_BEST_COMPRESSION); - NODE_DEFINE_CONSTANT(target, Z_DEFAULT_COMPRESSION); - NODE_DEFINE_CONSTANT(target, Z_FILTERED); - NODE_DEFINE_CONSTANT(target, Z_HUFFMAN_ONLY); - NODE_DEFINE_CONSTANT(target, Z_RLE); - NODE_DEFINE_CONSTANT(target, Z_FIXED); - NODE_DEFINE_CONSTANT(target, Z_DEFAULT_STRATEGY); - NODE_DEFINE_CONSTANT(target, ZLIB_VERNUM); - - NODE_DEFINE_CONSTANT(target, DEFLATE); - NODE_DEFINE_CONSTANT(target, INFLATE); - NODE_DEFINE_CONSTANT(target, GZIP); - NODE_DEFINE_CONSTANT(target, GUNZIP); - NODE_DEFINE_CONSTANT(target, DEFLATERAW); - NODE_DEFINE_CONSTANT(target, INFLATERAW); - NODE_DEFINE_CONSTANT(target, UNZIP); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ZLIB_VERSION"), FIXED_ONE_BYTE_STRING(env->isolate(), ZLIB_VERSION)); } diff --git a/test/parallel/test-zlib-const.js b/test/parallel/test-zlib-const.js index b7eb31d2c5..95238d7b5b 100644 --- a/test/parallel/test-zlib-const.js +++ b/test/parallel/test-zlib-const.js @@ -4,9 +4,9 @@ var assert = require('assert'); var zlib = require('zlib'); -assert.equal(zlib.Z_OK, 0, 'Z_OK should be 0'); -zlib.Z_OK = 1; -assert.equal(zlib.Z_OK, 0, 'Z_OK should be 0'); +assert.equal(zlib.constants.Z_OK, 0, 'Z_OK should be 0'); +zlib.constants.Z_OK = 1; +assert.equal(zlib.constants.Z_OK, 0, 'Z_OK should be 0'); assert.equal(zlib.codes.Z_OK, 0, 'Z_OK should be 0'); zlib.codes.Z_OK = 1; diff --git a/test/parallel/test-zlib-flush-flags.js b/test/parallel/test-zlib-flush-flags.js index 08c79f138b..5c7cba9a58 100644 --- a/test/parallel/test-zlib-flush-flags.js +++ b/test/parallel/test-zlib-flush-flags.js @@ -4,7 +4,7 @@ const assert = require('assert'); const zlib = require('zlib'); assert.doesNotThrow(() => { - zlib.createGzip({ flush: zlib.Z_SYNC_FLUSH }); + zlib.createGzip({ flush: zlib.constants.Z_SYNC_FLUSH }); }); assert.throws(() => { @@ -16,7 +16,7 @@ assert.throws(() => { }, /Invalid flush flag: 10000/); assert.doesNotThrow(() => { - zlib.createGzip({ finishFlush: zlib.Z_SYNC_FLUSH }); + zlib.createGzip({ finishFlush: zlib.constants.Z_SYNC_FLUSH }); }); assert.throws(() => { diff --git a/test/parallel/test-zlib-flush.js b/test/parallel/test-zlib-flush.js index 1bec5ff543..059f07018c 100644 --- a/test/parallel/test-zlib-flush.js +++ b/test/parallel/test-zlib-flush.js @@ -19,7 +19,7 @@ let actualNone; let actualFull; deflater.write(chunk, function() { - deflater.flush(zlib.Z_NO_FLUSH, function() { + deflater.flush(zlib.constants.Z_NO_FLUSH, function() { actualNone = deflater.read(); deflater.flush(function() { var bufs = [], buf; diff --git a/test/parallel/test-zlib-params.js b/test/parallel/test-zlib-params.js index eea47979e3..09c35ca599 100644 --- a/test/parallel/test-zlib-params.js +++ b/test/parallel/test-zlib-params.js @@ -7,7 +7,7 @@ var fs = require('fs'); const file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg')); const chunkSize = 12 * 1024; -const opts = { level: 9, strategy: zlib.Z_DEFAULT_STRATEGY }; +const opts = { level: 9, strategy: zlib.constants.Z_DEFAULT_STRATEGY }; const deflater = zlib.createDeflate(opts); const chunk1 = file.slice(0, chunkSize); @@ -17,7 +17,7 @@ const expected = Buffer.concat([blkhdr, chunk2]); let actual; deflater.write(chunk1, function() { - deflater.params(0, zlib.Z_DEFAULT_STRATEGY, function() { + deflater.params(0, zlib.constants.Z_DEFAULT_STRATEGY, function() { while (deflater.read()); deflater.end(chunk2, function() { var bufs = [], buf; diff --git a/test/parallel/test-zlib-sync-no-event.js b/test/parallel/test-zlib-sync-no-event.js index 81d1ad530d..46ea97fbf4 100644 --- a/test/parallel/test-zlib-sync-no-event.js +++ b/test/parallel/test-zlib-sync-no-event.js @@ -11,11 +11,11 @@ const zipper = new zlib.Gzip(); zipper.on('close', shouldNotBeCalled); const buffer = new Buffer(message); -const zipped = zipper._processChunk(buffer, zlib.Z_FINISH); +const zipped = zipper._processChunk(buffer, zlib.constants.Z_FINISH); const unzipper = new zlib.Gunzip(); unzipper.on('close', shouldNotBeCalled); -const unzipped = unzipper._processChunk(zipped, zlib.Z_FINISH); +const unzipped = unzipper._processChunk(zipped, zlib.constants.Z_FINISH); assert.notEqual(zipped.toString(), message); assert.strictEqual(unzipped.toString(), message); diff --git a/test/parallel/test-zlib-truncated.js b/test/parallel/test-zlib-truncated.js index da82acb657..88eb9f34ac 100644 --- a/test/parallel/test-zlib-truncated.js +++ b/test/parallel/test-zlib-truncated.js @@ -47,7 +47,7 @@ const inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing eli' assert(/unexpected end of file/.test(err.message)); }); - const syncFlushOpt = { finishFlush: zlib.Z_SYNC_FLUSH }; + const syncFlushOpt = { finishFlush: zlib.constants.Z_SYNC_FLUSH }; // sync truncated input test, finishFlush = Z_SYNC_FLUSH assert.doesNotThrow(function() { diff --git a/test/parallel/test-zlib-write-after-flush.js b/test/parallel/test-zlib-write-after-flush.js index fa70c5f14d..69211816e2 100644 --- a/test/parallel/test-zlib-write-after-flush.js +++ b/test/parallel/test-zlib-write-after-flush.js @@ -19,7 +19,7 @@ process.on('exit', function() { assert.equal(output, input); // Make sure that the flush flag was set back to normal - assert.equal(gzip._flushFlag, zlib.Z_NO_FLUSH); + assert.equal(gzip._flushFlag, zlib.constants.Z_NO_FLUSH); console.log('ok'); });