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:
parent
f1c7b5e29e
commit
883e9648d7
1 changed files with 12 additions and 8 deletions
|
@ -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):
|
||||||
|
|
Loading…
Reference in a new issue