Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the quality option OK? #38

Open
Joxter opened this issue Jun 9, 2022 · 1 comment
Open

Is the quality option OK? #38

Joxter opened this issue Jun 9, 2022 · 1 comment

Comments

@Joxter
Copy link

Joxter commented Jun 9, 2022

Hi, is the quality option in the compress function OK?

https://github.com/foliojs/brotli.js/blob/master/compress.js#L18=

  } else if (typeof opts === 'object') {
    quality = opts.quality || 11;
    mode = opts.mode || 0;
    lgwin = opts.lgwin || 22;
  }

README says quality could be 0, but then it should turn into 11. My tests confirm that 0 works like 11.

Where is a mistake? I am extremely sorry if I messed up something

@persunde
Copy link

My tests also showed that quality = 0 and quality = 11, results in the same compression quality.

As @Joxter pointed out, the source confirms my suspicion as the code uses a "fasly" check and that logic is incorrect when the quality value is 0. I am referring to this line:
quality = opts.quality || 11;

Instead the code should use the nullish coalescing (??) operator to check if the value is defined or not. Like this:
quality = opts.quality ?? 11;

I will submit a merge request soon when I have some extra time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants