From 8ce3ac0bfe86a5b2dbf6c234de0e7cea4f76188b Mon Sep 17 00:00:00 2001 From: xxyzz Date: Tue, 20 Aug 2024 18:16:14 +0800 Subject: [PATCH] Save download file to disk then decompress should prevent using partial downloaded file --- __init__.py | 2 +- deps.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 9288e45..33f122f 100644 --- a/__init__.py +++ b/__init__.py @@ -1,6 +1,6 @@ from calibre.customize import InterfaceActionBase -VERSION = (3, 33, 0) +VERSION = (3, 33, 1) class WordDumbDumb(InterfaceActionBase): diff --git a/deps.py b/deps.py index 035cc33..cbf9577 100644 --- a/deps.py +++ b/deps.py @@ -174,5 +174,9 @@ def download_word_wise_file( def download_and_extract(url: str, extract_path: Path) -> None: extract_path.parent.mkdir(parents=True, exist_ok=True) - with urlopen(url) as r, bz2.open(r) as bz2_f, extract_path.open("wb") as f: + download_path = extract_path.with_name(url.rsplit("/", 1)[-1]) + with urlopen(url) as r, open(download_path, "wb") as f: + shutil.copyfileobj(r, f) + with bz2.open(download_path) as bz2_f, extract_path.open("wb") as f: shutil.copyfileobj(bz2_f, f) + download_path.unlink()