summaryrefslogtreecommitdiff
path: root/lib/zlib.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/zlib.js')
-rw-r--r--lib/zlib.js80
1 files changed, 44 insertions, 36 deletions
diff --git a/lib/zlib.js b/lib/zlib.js
index 445a538035..4b34267318 100644
--- a/lib/zlib.js
+++ b/lib/zlib.js
@@ -21,7 +21,15 @@
'use strict';
-const { Math, Object } = primordials;
+const {
+ MathMax,
+ ObjectDefineProperties,
+ ObjectDefineProperty,
+ ObjectFreeze,
+ ObjectGetPrototypeOf,
+ ObjectKeys,
+ ObjectSetPrototypeOf,
+} = primordials;
const {
codes: {
@@ -80,7 +88,7 @@ const codes = {
Z_VERSION_ERROR: constants.Z_VERSION_ERROR
};
-const ckeys = Object.keys(codes);
+const ckeys = ObjectKeys(codes);
for (var ck = 0; ck < ckeys.length; ck++) {
var ckey = ckeys[ck];
codes[codes[ckey]] = ckey;
@@ -92,7 +100,7 @@ function zlibBuffer(engine, buffer, callback) {
// Streams do not support non-Buffer ArrayBufferViews yet. Convert it to a
// Buffer without copying.
if (isArrayBufferView(buffer) &&
- Object.getPrototypeOf(buffer) !== Buffer.prototype) {
+ ObjectGetPrototypeOf(buffer) !== Buffer.prototype) {
buffer = Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
} else if (isAnyArrayBuffer(buffer)) {
buffer = Buffer.from(buffer);
@@ -267,10 +275,10 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
this.once('end', this.close);
this._info = opts && opts.info;
}
-Object.setPrototypeOf(ZlibBase.prototype, Transform.prototype);
-Object.setPrototypeOf(ZlibBase, Transform);
+ObjectSetPrototypeOf(ZlibBase.prototype, Transform.prototype);
+ObjectSetPrototypeOf(ZlibBase, Transform);
-Object.defineProperty(ZlibBase.prototype, '_closed', {
+ObjectDefineProperty(ZlibBase.prototype, '_closed', {
configurable: true,
enumerable: true,
get() {
@@ -282,7 +290,7 @@ Object.defineProperty(ZlibBase.prototype, '_closed', {
// perspective, but it is inconsistent with all other streams exposed by Node.js
// that have this concept, where it stands for the number of bytes read
// *from* the stream (that is, net.Socket/tls.Socket & file system streams).
-Object.defineProperty(ZlibBase.prototype, 'bytesRead', {
+ObjectDefineProperty(ZlibBase.prototype, 'bytesRead', {
configurable: true,
enumerable: true,
get: deprecate(function() {
@@ -661,8 +669,8 @@ function Zlib(opts, mode) {
this._level = level;
this._strategy = strategy;
}
-Object.setPrototypeOf(Zlib.prototype, ZlibBase.prototype);
-Object.setPrototypeOf(Zlib, ZlibBase);
+ObjectSetPrototypeOf(Zlib.prototype, ZlibBase.prototype);
+ObjectSetPrototypeOf(Zlib, ZlibBase);
// This callback is used by `.params()` to wait until a full flush happened
// before adjusting the parameters. In particular, the call to the native
@@ -697,32 +705,32 @@ function Deflate(opts) {
return new Deflate(opts);
Zlib.call(this, opts, DEFLATE);
}
-Object.setPrototypeOf(Deflate.prototype, Zlib.prototype);
-Object.setPrototypeOf(Deflate, Zlib);
+ObjectSetPrototypeOf(Deflate.prototype, Zlib.prototype);
+ObjectSetPrototypeOf(Deflate, Zlib);
function Inflate(opts) {
if (!(this instanceof Inflate))
return new Inflate(opts);
Zlib.call(this, opts, INFLATE);
}
-Object.setPrototypeOf(Inflate.prototype, Zlib.prototype);
-Object.setPrototypeOf(Inflate, Zlib);
+ObjectSetPrototypeOf(Inflate.prototype, Zlib.prototype);
+ObjectSetPrototypeOf(Inflate, Zlib);
function Gzip(opts) {
if (!(this instanceof Gzip))
return new Gzip(opts);
Zlib.call(this, opts, GZIP);
}
-Object.setPrototypeOf(Gzip.prototype, Zlib.prototype);
-Object.setPrototypeOf(Gzip, Zlib);
+ObjectSetPrototypeOf(Gzip.prototype, Zlib.prototype);
+ObjectSetPrototypeOf(Gzip, Zlib);
function Gunzip(opts) {
if (!(this instanceof Gunzip))
return new Gunzip(opts);
Zlib.call(this, opts, GUNZIP);
}
-Object.setPrototypeOf(Gunzip.prototype, Zlib.prototype);
-Object.setPrototypeOf(Gunzip, Zlib);
+ObjectSetPrototypeOf(Gunzip.prototype, Zlib.prototype);
+ObjectSetPrototypeOf(Gunzip, Zlib);
function DeflateRaw(opts) {
if (opts && opts.windowBits === 8) opts.windowBits = 9;
@@ -730,24 +738,24 @@ function DeflateRaw(opts) {
return new DeflateRaw(opts);
Zlib.call(this, opts, DEFLATERAW);
}
-Object.setPrototypeOf(DeflateRaw.prototype, Zlib.prototype);
-Object.setPrototypeOf(DeflateRaw, Zlib);
+ObjectSetPrototypeOf(DeflateRaw.prototype, Zlib.prototype);
+ObjectSetPrototypeOf(DeflateRaw, Zlib);
function InflateRaw(opts) {
if (!(this instanceof InflateRaw))
return new InflateRaw(opts);
Zlib.call(this, opts, INFLATERAW);
}
-Object.setPrototypeOf(InflateRaw.prototype, Zlib.prototype);
-Object.setPrototypeOf(InflateRaw, Zlib);
+ObjectSetPrototypeOf(InflateRaw.prototype, Zlib.prototype);
+ObjectSetPrototypeOf(InflateRaw, Zlib);
function Unzip(opts) {
if (!(this instanceof Unzip))
return new Unzip(opts);
Zlib.call(this, opts, UNZIP);
}
-Object.setPrototypeOf(Unzip.prototype, Zlib.prototype);
-Object.setPrototypeOf(Unzip, Zlib);
+ObjectSetPrototypeOf(Unzip.prototype, Zlib.prototype);
+ObjectSetPrototypeOf(Unzip, Zlib);
function createConvenienceMethod(ctor, sync) {
if (sync) {
@@ -765,7 +773,7 @@ function createConvenienceMethod(ctor, sync) {
}
}
-const kMaxBrotliParam = Math.max(...Object.keys(constants).map((key) => {
+const kMaxBrotliParam = MathMax(...ObjectKeys(constants).map((key) => {
return key.startsWith('BROTLI_PARAM_') ? constants[key] : 0;
}));
@@ -781,7 +789,7 @@ function Brotli(opts, mode) {
brotliInitParamsArray.fill(-1);
if (opts && opts.params) {
- for (const origKey of Object.keys(opts.params)) {
+ for (const origKey of ObjectKeys(opts.params)) {
const key = +origKey;
if (Number.isNaN(key) || key < 0 || key > kMaxBrotliParam ||
(brotliInitParamsArray[key] | 0) !== -1) {
@@ -809,24 +817,24 @@ function Brotli(opts, mode) {
ZlibBase.call(this, opts, mode, handle, brotliDefaultOpts);
}
-Object.setPrototypeOf(Brotli.prototype, Zlib.prototype);
-Object.setPrototypeOf(Brotli, Zlib);
+ObjectSetPrototypeOf(Brotli.prototype, Zlib.prototype);
+ObjectSetPrototypeOf(Brotli, Zlib);
function BrotliCompress(opts) {
if (!(this instanceof BrotliCompress))
return new BrotliCompress(opts);
Brotli.call(this, opts, BROTLI_ENCODE);
}
-Object.setPrototypeOf(BrotliCompress.prototype, Brotli.prototype);
-Object.setPrototypeOf(BrotliCompress, Brotli);
+ObjectSetPrototypeOf(BrotliCompress.prototype, Brotli.prototype);
+ObjectSetPrototypeOf(BrotliCompress, Brotli);
function BrotliDecompress(opts) {
if (!(this instanceof BrotliDecompress))
return new BrotliDecompress(opts);
Brotli.call(this, opts, BROTLI_DECODE);
}
-Object.setPrototypeOf(BrotliDecompress.prototype, Brotli.prototype);
-Object.setPrototypeOf(BrotliDecompress, Brotli);
+ObjectSetPrototypeOf(BrotliDecompress.prototype, Brotli.prototype);
+ObjectSetPrototypeOf(BrotliDecompress, Brotli);
function createProperty(ctor) {
@@ -841,7 +849,7 @@ function createProperty(ctor) {
// Legacy alias on the C++ wrapper object. This is not public API, so we may
// want to runtime-deprecate it at some point. There's no hurry, though.
-Object.defineProperty(binding.Zlib.prototype, 'jsref', {
+ObjectDefineProperty(binding.Zlib.prototype, 'jsref', {
get() { return this[owner_symbol]; },
set(v) { return this[owner_symbol] = v; }
});
@@ -879,7 +887,7 @@ module.exports = {
brotliDecompressSync: createConvenienceMethod(BrotliDecompress, true),
};
-Object.defineProperties(module.exports, {
+ObjectDefineProperties(module.exports, {
createDeflate: createProperty(Deflate),
createInflate: createProperty(Inflate),
createDeflateRaw: createProperty(DeflateRaw),
@@ -897,17 +905,17 @@ Object.defineProperties(module.exports, {
codes: {
enumerable: true,
writable: false,
- value: Object.freeze(codes)
+ value: ObjectFreeze(codes)
}
});
// These should be considered deprecated
// expose all the zlib constants
-const bkeys = Object.keys(constants);
+const bkeys = ObjectKeys(constants);
for (var bk = 0; bk < bkeys.length; bk++) {
var bkey = bkeys[bk];
if (bkey.startsWith('BROTLI')) continue;
- Object.defineProperty(module.exports, bkey, {
+ ObjectDefineProperty(module.exports, bkey, {
enumerable: false, value: constants[bkey], writable: false
});
}