refactor: one digest loop for files and streams

This commit is contained in:
Abdessamad Derraz committed 2026-11-18 21:42:28 +01:00
1 parent 88581cf95d
commit 2c8a9cfad8
11 files changed
+88 -98

No files matched your search

+2 -5
View File
@@ -2,12 +2,12 @@
from __future__ import annotations
import hashlib
import io
import zipfile
from collections.abc import Callable
from pathlib import Path
from core.hashing import stream_hashes
from core.torrentzip import Source as Readable
@@ -39,8 +39,5 @@ def _opener(source: Path, member: str | None) -> Callable[[], Readable]:
def _member_sha1(path: Path, name: str) -> str:
digest = hashlib.sha1()
with _Member(path, name) as stream:
while chunk := stream.read(16 * 1024 * 1024):
digest.update(chunk)
return digest.hexdigest()
return stream_hashes(stream, frozenset({"sha1"}))["sha1"]