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

Skip compression of already compressed files #347

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/whitenoise/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ def compress(self, path):
stat_result = os.fstat(f.fileno())
data = f.read()
size = len(data)
if self.use_brotli:
if self.use_brotli and not os.path.isfile(f"{path}.br"):
compressed = self.compress_brotli(data)
if self.is_compressed_effectively("Brotli", path, size, compressed):
yield self.write_data(path, compressed, ".br", stat_result)
else:
# If Brotli compression wasn't effective gzip won't be either
return
if self.use_gzip:
if self.use_gzip and not os.path.isfile(f"{path}.gz"):
compressed = self.compress_gzip(data)
if self.is_compressed_effectively("Gzip", path, size, compressed):
yield self.write_data(path, compressed, ".gz", stat_result)
Expand Down