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

Develop #127

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Develop #127

wants to merge 5 commits into from

Conversation

arthurfujii
Copy link

No description provided.

Copy link

@pedro-ruas pedro-ruas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimal improvement suggestions. Noice!

return;
}

if (req.url === '/compress' && req.method === 'GET') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message from the error and the test are not aligned here.
Your are testing if the method is GET, and the error says you allow only POST.
So, what's the problem? If someone sent a PUT, would this test block it? Nope.
Is PUT the same as POST? Also nope.

So, the test you are looking for is: req.method !== 'POST'

compressorType = zlib.createDeflate();
} else {
res.statusCode = 400;
res.end('unsupported compression type');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else will never run, so you can remove it.
It won't ever run, because the if in line 43 of your code already tests it.
The same reasons that would make the test fail here are the ones that make it fail before, so it will never reach this point

`attachment; filename=${file[0].originalFilename}.${compressionType[0]}`,
);

let compressorType;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but you could try:
declaring your previous Object literal here, might work just like this, but better:

const compressors = {
  gzip: zlib.createGzip,
  br: zlib.createBrotliCompress,
  deflate: zlib.createDeflate,
};

const compressorType = compressors[compressionType[0]]();

See how I did not call the functions inside the compressors object, but only in compressorType, after I already know which will be used.

And, if you store this compressors object before line 43, you can even replace !['gzip, 'br', 'deflate'].includes... for !Object.keys(compressors).includes...
Allowing your coed to be easily extendable later on(you would only need to change the compressors object)

Copy link

@pedro-ruas pedro-ruas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flawless!

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

Successfully merging this pull request may close these issues.

2 participants