diff --git a/hera_librarian/client.py b/hera_librarian/client.py index abaf30a..279badc 100644 --- a/hera_librarian/client.py +++ b/hera_librarian/client.py @@ -90,8 +90,11 @@ class LibrarianClient: port: int user: str password: str + checksum_threads: int = 1 - def __init__(self, host: str, port: int, user: str, password: str): + def __init__( + self, host: str, port: int, user: str, password: str, checksum_threads: int = 1 + ): """ Create a new LibrarianClient. @@ -105,6 +108,8 @@ def __init__(self, host: str, port: int, user: str, password: str): The name of the user. password : str The password of the user. + checksum_threads : int + The number of threads to use for checksum computation. Default is 1. """ if host[-1] == "/": @@ -115,6 +120,7 @@ def __init__(self, host: str, port: int, user: str, password: str): self.port = port self.user = user self.password = password + self.checksum_threads = checksum_threads def __repr__(self): return f"Librarian Client ({self.user}) for {self.host}:{self.port}" @@ -394,7 +400,9 @@ def upload( endpoint="upload/stage", request=UploadInitiationRequest( upload_size=get_size_from_path(local_path), - upload_checksum=get_checksum_from_path(local_path, threads=1), + upload_checksum=get_checksum_from_path( + local_path, threads=self.checksum_threads + ), upload_name=dest_path.name, destination_location=dest_path, uploader=self.user, diff --git a/hera_librarian/utils.py b/hera_librarian/utils.py index fcdadbc..8cc8809 100644 --- a/hera_librarian/utils.py +++ b/hera_librarian/utils.py @@ -95,19 +95,11 @@ def individual( def _filehash(filepath, hashfunc): - hasher = hashfunc() - blocksize = 64 * 1024 - if not os.path.exists(filepath): - return hasher.hexdigest() + return hashfunc().hexdigest() with open(filepath, "rb") as fp: - while True: - data = fp.read(blocksize) - if not data: - break - hasher.update(data) - return hasher.hexdigest() + return hashlib.file_digest(fp, hashfunc).hexdigest() def _reduce_hash(hashlist, hashfunc): diff --git a/pyproject.toml b/pyproject.toml index 0ca20f1..b3eb5ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ exclude=["*tests*"] [project] name="hera_librarian" requires-python = ">=3.10" -version = "5.0.1" +version = "5.1.0" dependencies = [ "alembic", "argon2-cffi", diff --git a/tests/integration_test/test_secondary_server.py b/tests/integration_test/test_secondary_server.py index cc561be..0f37805 100644 --- a/tests/integration_test/test_secondary_server.py +++ b/tests/integration_test/test_secondary_server.py @@ -19,7 +19,7 @@ def test_secondary_server_simple( response = test_client.post( "/api/v2/ping", - content=PingRequest().model_dump_json(), + json=PingRequest().model_dump(), auth=("admin", "password"), )