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.
This commit is contained in:
Chase Roohms
2026-04-05 22:43:46 -05:00
committed by GitHub
parent d37be87c2f
commit caead0a957
+4 -4
View File
@@ -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,