Skip to content

Commit

Permalink
Save download file to disk then decompress
Browse files Browse the repository at this point in the history
should prevent using partial downloaded file
  • Loading branch information
xxyzz committed Aug 20, 2024
1 parent af6ad70 commit 8ce3ac0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from calibre.customize import InterfaceActionBase

VERSION = (3, 33, 0)
VERSION = (3, 33, 1)


class WordDumbDumb(InterfaceActionBase):
Expand Down
6 changes: 5 additions & 1 deletion deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 8ce3ac0

Please sign in to comment.