From 9ef572f05eb385eb8f196545811ba3e24315d1e0 Mon Sep 17 00:00:00 2001 From: Oleskii Pyskun Date: Tue, 2 Jul 2024 12:58:31 +0300 Subject: [PATCH] Implementation save to file page --- cbz/comic.py | 9 +++++++++ cbz/page.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/cbz/comic.py b/cbz/comic.py index e840c36..092307a 100644 --- a/cbz/comic.py +++ b/cbz/comic.py @@ -175,3 +175,12 @@ class ComicInfo(ComicModel): :return: """ return self.__pages + + def save_page(self, index: int, path: Union[Path, str]) -> None: + """ + Save page to the file + :param index: page index + :param path: path to new file, str or Path + :return: + """ + self.__pages[index].save(path) diff --git a/cbz/page.py b/cbz/page.py index 5410e21..29e0beb 100644 --- a/cbz/page.py +++ b/cbz/page.py @@ -68,3 +68,12 @@ class PageInfo(PageModel): """ with Image.open(BytesIO(self.content)) as image: image.show() + + def save(self, path: Union[Path, str]): + """ + Save page to file + :param path: + :return: + """ + with Path(path).open(mode='wb') as f: + f.write(self.content)