mirror of
https://github.com/hyugogirubato/cbz.git
synced 2026-09-26 21:41:03 +00:00
Merge pull request #30 from chase-roohms/patch-1
Add compression argument to pack and unpack methods
This commit is contained in:
+5
-5
@@ -176,7 +176,7 @@ class ComicInfo(ComicModel):
|
|||||||
|
|
||||||
# Some archives may contain folders or hidden files (e.g., ".extra/" or "__MACOSX/.DS_Store")
|
# 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.
|
# 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})')
|
logging.warning(f'Skipping unsupported or invalid file: {name!r} (suffix={suffix!r})')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ class ComicInfo(ComicModel):
|
|||||||
return ComicInfo.__process_archive(rf)
|
return ComicInfo.__process_archive(rf)
|
||||||
|
|
||||||
@staticmethod
|
@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.
|
Unpack a CBZ file and create a ComicInfo instance.
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ class ComicInfo(ComicModel):
|
|||||||
Returns:
|
Returns:
|
||||||
ComicInfo: An instance of ComicInfo.
|
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)
|
return ComicInfo.__process_archive(zf)
|
||||||
|
|
||||||
def get_info(self) -> dict:
|
def get_info(self) -> dict:
|
||||||
@@ -271,7 +271,7 @@ class ComicInfo(ComicModel):
|
|||||||
})
|
})
|
||||||
return comic_info
|
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.
|
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.
|
bytes: Bytes representing the packed CBZ file.
|
||||||
"""
|
"""
|
||||||
zip_buffer = BytesIO()
|
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)
|
content = xmltodict.unparse({'ComicInfo': self.get_info()}, pretty=True)
|
||||||
zf.writestr(
|
zf.writestr(
|
||||||
XML_NAME,
|
XML_NAME,
|
||||||
|
|||||||
Reference in New Issue
Block a user