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

Cache: only re-encode if maximum quality wasn't used originally #54

Open
OliverJAsh opened this issue May 12, 2020 · 1 comment
Open

Comments

@OliverJAsh
Copy link

It seems that this module will asynchronously re-encode at the best/maximum quality, even if the maximum quality was used originally. IIUC, this means that if you ask for the maximum quality, shrink-ray will end up compressing the resource twice at the maximum quality.

I think we need to add a guard around the re-encode, so that it only runs if maximum quality wasn't already used:

shrink-ray/index.js

Lines 411 to 422 in f7cfcc7

// now asynchronously re-encode the entry at best quality
const result = new BufferWritable();
new BufferReadable(buffer)
.pipe(getBestQualityReencoder(coding, zopfli))
.pipe(result)
.on('finish', function () {
const itemInCache = lru.peek(key);
if (itemInCache) {
itemInCache.buffer = result.toBuffer();
}
});

@OliverJAsh
Copy link
Author

Hi @Alorel would you accept a PR to fix this?

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

1 participant