From caead0a957f061f8e0b3334411ba072d91cd6529 Mon Sep 17 00:00:00 2001 From: Chase Roohms Date: Sun, 5 Apr 2026 22:43:46 -0500 Subject: [PATCH 1/2] Add compression argument to unpack_zip and pack methods Updated the __unpack_zip and pack methods to accept a compression argument for more flexibility in handling zip files. --- cbz/comic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cbz/comic.py b/cbz/comic.py index ae414ef..af9b116 100644 --- a/cbz/comic.py +++ b/cbz/comic.py @@ -207,7 +207,7 @@ class ComicInfo(ComicModel): return ComicInfo.__process_archive(rf) @staticmethod - def __unpack_zip(path: Path) -> ComicInfo: + def __unpack_zip(path: Path, compression: int = zipfile.ZIP_STORED) -> ComicInfo: """ Unpack a CBZ file and create a ComicInfo instance. @@ -217,7 +217,7 @@ class ComicInfo(ComicModel): Returns: ComicInfo: An instance of ComicInfo. """ - with zipfile.ZipFile(path, 'r', zipfile.ZIP_STORED) as zf: + with zipfile.ZipFile(path, 'r', compression) as zf: return ComicInfo.__process_archive(zf) def get_info(self) -> dict: @@ -271,7 +271,7 @@ class ComicInfo(ComicModel): }) return comic_info - def pack(self, rename: bool = True) -> bytes: + def pack(self, rename: bool = True, compression: int = zipfile.ZIP_STORED) -> bytes: """ Pack the comic information and pages into a CBZ file format. @@ -282,7 +282,7 @@ class ComicInfo(ComicModel): bytes: Bytes representing the packed CBZ file. """ zip_buffer = BytesIO() - with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_STORED) as zf: + with zipfile.ZipFile(zip_buffer, 'w', compression) as zf: content = xmltodict.unparse({'ComicInfo': self.get_info()}, pretty=True) zf.writestr( XML_NAME, From 4d4d367791ad1f573a53eeceec2c842627fc570f Mon Sep 17 00:00:00 2001 From: Chase Roohms Date: Sun, 5 Apr 2026 22:51:26 -0500 Subject: [PATCH 2/2] Normalize suffix check to lowercase for image formats All entries in IMAGE_FORMATS are lowercase, this incorrectly fails on extensions like "JPG" --- cbz/comic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbz/comic.py b/cbz/comic.py index af9b116..21bed52 100644 --- a/cbz/comic.py +++ b/cbz/comic.py @@ -176,7 +176,7 @@ class ComicInfo(ComicModel): # Some archives may contain folders or hidden files (e.g., ".extra/" or "__MACOSX/.DS_Store") # that could corrupt the suffix detection and cause invalid image handling. - if suffix not in IMAGE_FORMAT: + if suffix.lower() not in IMAGE_FORMAT: logging.warning(f'Skipping unsupported or invalid file: {name!r} (suffix={suffix!r})') continue