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

fix: Disable zip compression on ROM download #983

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions backend/endpoints/rom.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from collections.abc import Iterator
from datetime import datetime
from shutil import rmtree
from stat import S_IFREG
Expand Down Expand Up @@ -208,7 +209,7 @@ def get_rom_content(
raise RomNotFoundInDatabaseException(id)

rom_path = f"{LIBRARY_BASE_PATH}/{rom.full_path}"
files_to_download = files or rom.files
files_to_download = files or rom.files or []

if not rom.multi:
return FileResponse(path=rom_path, filename=rom.file_name)
Expand All @@ -220,34 +221,33 @@ def get_rom_content(

# Builds a generator of tuples for each member file
def local_files():
def contents(f):
def contents(filename: str) -> Iterator[bytes]:
try:
with open(f"{rom_path}/{f}", "rb") as f:
with open(f"{rom_path}/{filename}", "rb") as f:
while chunk := f.read(65536):
yield chunk
except FileNotFoundError:
log.error(f"File {rom_path}/{f} not found!")
log.error(f"File {rom_path}/{filename} not found!")
raise

m3u_file = [
str.encode(f"{files_to_download[i]}\n")
for i in range(len(files_to_download))
]
m3u_file = [str.encode(f"{file}\n") for file in files_to_download]
now = datetime.now()

return [
(
f,
datetime.now(),
now,
S_IFREG | 0o600,
ZIP_AUTO(os.path.getsize(f"{rom_path}/{f}")),
ZIP_AUTO(os.path.getsize(f"{rom_path}/{f}"), level=0),
contents(f),
)
for f in files_to_download
] + [
(
f"{file_name}.m3u",
datetime.now(),
now,
S_IFREG | 0o600,
ZIP_AUTO(sum([len(f) for f in m3u_file])),
ZIP_AUTO(sum([len(f) for f in m3u_file]), level=0),
m3u_file,
)
]
Expand Down
Loading