1
0
Fork 0
mirror of https://github.com/Findus23/PaperLibrary-cli.git synced 2024-09-20 17:03:46 +02:00

speed up hash

This commit is contained in:
Lukas Winkler 2024-04-17 16:57:07 +02:00
parent f1c7b5e29e
commit 883e9648d7
Signed by: lukas
GPG key ID: 54DE4D798D244853

View file

@ -119,14 +119,18 @@ def download_file(api: PaperLibraryAPI, url: str, target_file: Path):
def hash_file(file: Path, buffer_size=65536) -> str: def hash_file(file: Path, buffer_size=65536) -> str:
sha256 = hashlib.sha256() try:
with file.open("rb") as f: with file.open("rb") as f:
while True: return hashlib.file_digest(f, "sha256").hexdigest()
data = f.read(buffer_size) except AttributeError:
if not data: sha256 = hashlib.sha256()
break with file.open("rb") as f:
sha256.update(data) while True:
return sha256.hexdigest() data = f.read(buffer_size)
if not data:
break
sha256.update(data)
return sha256.hexdigest()
def update_pdfs(api: PaperLibraryAPI, config: Config): def update_pdfs(api: PaperLibraryAPI, config: Config):