Fixes compressed downloads (#5014)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
F.D.Castel 2023-06-27 20:13:14 -03:00 committed by Jesse Hills
parent 70de2f5278
commit 832ba38f1b
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A

View File

@ -546,22 +546,11 @@ class DownloadBinaryRequestHandler(BaseHandler):
return
with open(path, "rb") as f:
while True:
# For a 528KB image used as benchmark:
# - using 256KB blocks resulted in the smallest file size.
# - blocks larger than 256KB didn't improve the size of compressed file.
# - blocks smaller than 256KB hindered compression, making the output file larger.
# Read file in blocks of 256KB.
data = f.read(256 * 1024)
if not data:
break
data = f.read()
if compressed:
data = gzip.compress(data, 9)
self.write(data)
self.finish()