23
23
24
24
const {
25
25
ArrayBuffer,
26
- ArrayPrototypeForEach,
27
- ArrayPrototypeMap,
28
- ArrayPrototypePush,
29
- FunctionPrototypeBind,
30
- MathMaxApply,
26
+ MathMax,
31
27
NumberIsNaN,
32
28
ObjectDefineProperties,
33
29
ObjectDefineProperty,
30
+ ObjectEntries,
34
31
ObjectFreeze,
35
32
ObjectKeys,
36
33
ObjectSetPrototypeOf,
37
34
ReflectApply,
38
- StringPrototypeStartsWith,
39
35
Symbol,
40
- TypedArrayPrototypeFill,
41
36
Uint32Array,
42
37
} = primordials ;
43
38
@@ -130,10 +125,11 @@ function zlibBuffer(engine, buffer, callback) {
130
125
}
131
126
132
127
function zlibBufferOnData ( chunk ) {
133
- if ( ! this . buffers )
128
+ if ( ! this . buffers ) {
134
129
this . buffers = [ chunk ] ;
135
- else
136
- ArrayPrototypePush ( this . buffers , chunk ) ;
130
+ } else {
131
+ this . buffers . push ( chunk ) ;
132
+ }
137
133
this . nread += chunk . length ;
138
134
if ( this . nread > this . _maxOutputLength ) {
139
135
this . close ( ) ;
@@ -442,7 +438,7 @@ function processChunkSync(self, chunk, flushFlag) {
442
438
if ( have > 0 ) {
443
439
const out = buffer . slice ( offset , offset + have ) ;
444
440
offset += have ;
445
- ArrayPrototypePush ( buffers , out ) ;
441
+ buffers . push ( out ) ;
446
442
nread += out . byteLength ;
447
443
448
444
if ( nread > self . _maxOutputLength ) {
@@ -700,9 +696,10 @@ Zlib.prototype.params = function params(level, strategy, callback) {
700
696
checkRangesOrGetDefault ( strategy , 'strategy' , Z_DEFAULT_STRATEGY , Z_FIXED ) ;
701
697
702
698
if ( this . _level !== level || this . _strategy !== strategy ) {
703
- this . flush ( Z_SYNC_FLUSH ,
704
- FunctionPrototypeBind ( paramsAfterFlushCallback , this ,
705
- level , strategy , callback ) ) ;
699
+ this . flush (
700
+ Z_SYNC_FLUSH ,
701
+ paramsAfterFlushCallback . bind ( this , level , strategy , callback ) ,
702
+ ) ;
706
703
} else {
707
704
process . nextTick ( callback ) ;
708
705
}
@@ -782,13 +779,10 @@ function createConvenienceMethod(ctor, sync) {
782
779
} ;
783
780
}
784
781
785
- const kMaxBrotliParam = MathMaxApply ( ArrayPrototypeMap (
786
- ObjectKeys ( constants ) ,
787
- ( key ) => ( StringPrototypeStartsWith ( key , 'BROTLI_PARAM_' ) ?
788
- constants [ key ] :
789
- 0 ) ,
790
- ) ) ;
791
-
782
+ const kMaxBrotliParam = MathMax (
783
+ ...ObjectEntries ( constants )
784
+ . map ( ( { 0 : key , 1 : value } ) => ( key . startsWith ( 'BROTLI_PARAM_' ) ? value : 0 ) ) ,
785
+ ) ;
792
786
const brotliInitParamsArray = new Uint32Array ( kMaxBrotliParam + 1 ) ;
793
787
794
788
const brotliDefaultOpts = {
@@ -799,9 +793,9 @@ const brotliDefaultOpts = {
799
793
function Brotli ( opts , mode ) {
800
794
assert ( mode === BROTLI_DECODE || mode === BROTLI_ENCODE ) ;
801
795
802
- TypedArrayPrototypeFill ( brotliInitParamsArray , - 1 ) ;
796
+ brotliInitParamsArray . fill ( - 1 ) ;
803
797
if ( opts ?. params ) {
804
- ArrayPrototypeForEach ( ObjectKeys ( opts . params ) , ( origKey ) => {
798
+ ObjectKeys ( opts . params ) . forEach ( ( origKey ) => {
805
799
const key = + origKey ;
806
800
if ( NumberIsNaN ( key ) || key < 0 || key > kMaxBrotliParam ||
807
801
( brotliInitParamsArray [ key ] | 0 ) !== - 1 ) {
@@ -939,10 +933,12 @@ ObjectDefineProperties(module.exports, {
939
933
940
934
// These should be considered deprecated
941
935
// expose all the zlib constants
942
- for ( const bkey of ObjectKeys ( constants ) ) {
943
- if ( StringPrototypeStartsWith ( bkey , 'BROTLI' ) ) continue ;
944
- ObjectDefineProperty ( module . exports , bkey , {
936
+ for ( const { 0 : key , 1 : value } of ObjectEntries ( constants ) ) {
937
+ if ( key . startsWith ( 'BROTLI' ) ) continue ;
938
+ ObjectDefineProperty ( module . exports , key , {
945
939
__proto__ : null ,
946
- enumerable : false , value : constants [ bkey ] , writable : false ,
940
+ enumerable : false ,
941
+ value,
942
+ writable : false ,
947
943
} ) ;
948
944
}
0 commit comments