Skip to content

Commit

Permalink
Apply default value also when params is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jul 13, 2020
1 parent f77283d commit 48c4f2e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions index.js
Expand Up @@ -67,10 +67,17 @@ var supportedEncodingsNoDeflate = hasBrotliSupport
function compression (options) {
var opts = options || {}

if (hasBrotliSupport && opts.params === undefined) {
opts = objectAssign({}, opts)
opts.params = {}
opts.params[zlib.constants.BROTLI_PARAM_QUALITY] = 4
if (hasBrotliSupport) {
// set the default level to a reasonable value with balanced speed/ratio
if (opts.params === undefined) {
opts = objectAssign({}, opts)
opts.params = {}
}

if (opts.params[zlib.constants.BROTLI_PARAM_QUALITY] === undefined) {
opts.params = objectAssign({}, opts.params)
opts.params[zlib.constants.BROTLI_PARAM_QUALITY] = 4
}
}

// options
Expand Down

0 comments on commit 48c4f2e

Please sign in to comment.