diff --git a/swh/objstorage/api/client.py b/swh/objstorage/api/client.py --- a/swh/objstorage/api/client.py +++ b/swh/objstorage/api/client.py @@ -8,9 +8,11 @@ from swh.model import hashutil from swh.objstorage.exc import Error, ObjNotFoundError, ObjStorageAPIError from swh.objstorage.interface import ObjStorageInterface -from swh.objstorage.objstorage import DEFAULT_CHUNK_SIZE, DEFAULT_LIMIT - -SHA1_SIZE = 20 +from swh.objstorage.objstorage import ( + DEFAULT_CHUNK_SIZE, + DEFAULT_LIMIT, + ID_DIGEST_LENGTH, +) class RemoteObjStorage(RPCClient): @@ -50,5 +52,5 @@ if last_obj_id: params["last_obj_id"] = hashutil.hash_to_hex(last_obj_id) yield from iter_chunks( - self._get_stream("content", params=params), chunk_size=SHA1_SIZE + self._get_stream("content", params=params), chunk_size=ID_DIGEST_LENGTH ) diff --git a/swh/objstorage/backends/pathslicing.py b/swh/objstorage/backends/pathslicing.py --- a/swh/objstorage/backends/pathslicing.py +++ b/swh/objstorage/backends/pathslicing.py @@ -17,7 +17,7 @@ DEFAULT_CHUNK_SIZE, DEFAULT_LIMIT, ID_HASH_ALGO, - ID_HASH_LENGTH, + ID_HEXDIGEST_LENGTH, ObjStorage, compressors, compute_hash, @@ -74,7 +74,7 @@ max_char = max( max(bound.start or 0, bound.stop or 0) for bound in self.bounds ) - if ID_HASH_LENGTH < max_char: + if ID_HEXDIGEST_LENGTH < max_char: raise ValueError( "Algorithm %s has too short hash for slicing to char %d" % (ID_HASH_ALGO, max_char) @@ -119,7 +119,7 @@ a list. """ - assert len(hex_obj_id) == ID_HASH_LENGTH + assert len(hex_obj_id) == ID_HEXDIGEST_LENGTH return [hex_obj_id[bound] for bound in self.bounds] def __len__(self) -> int: diff --git a/swh/objstorage/factory.py b/swh/objstorage/factory.py --- a/swh/objstorage/factory.py +++ b/swh/objstorage/factory.py @@ -16,7 +16,7 @@ from swh.objstorage.backends.winery import WineryObjStorage from swh.objstorage.multiplexer import MultiplexerObjStorage, StripingObjStorage from swh.objstorage.multiplexer.filter import add_filters -from swh.objstorage.objstorage import ID_HASH_LENGTH, ObjStorage # noqa +from swh.objstorage.objstorage import ID_HEXDIGEST_LENGTH, ObjStorage # noqa __all__ = ["get_objstorage", "ObjStorage"] diff --git a/swh/objstorage/objstorage.py b/swh/objstorage/objstorage.py --- a/swh/objstorage/objstorage.py +++ b/swh/objstorage/objstorage.py @@ -15,9 +15,18 @@ from .exc import ObjNotFoundError ID_HASH_ALGO = "sha1" -ID_HASH_LENGTH = 40 # Size in bytes of the hash hexadecimal representation. -DEFAULT_CHUNK_SIZE = 2 * 1024 * 1024 # Size in bytes of the streaming chunks + +ID_HEXDIGEST_LENGTH = 40 +"""Size in bytes of the hash hexadecimal representation.""" + +ID_DIGEST_LENGTH = 20 +"""Size in bytes of the hash""" + +DEFAULT_CHUNK_SIZE = 2 * 1024 * 1024 +"""Size in bytes of the streaming chunks""" + DEFAULT_LIMIT = 10000 +"""Default number of results of ``list_content``.""" def compute_hash(content): diff --git a/swh/objstorage/tests/test_objstorage_pathslicing.py b/swh/objstorage/tests/test_objstorage_pathslicing.py --- a/swh/objstorage/tests/test_objstorage_pathslicing.py +++ b/swh/objstorage/tests/test_objstorage_pathslicing.py @@ -11,7 +11,7 @@ from swh.model import hashutil from swh.objstorage import exc from swh.objstorage.factory import get_objstorage -from swh.objstorage.objstorage import ID_HASH_LENGTH +from swh.objstorage.objstorage import ID_DIGEST_LENGTH from .objstorage_testing import ObjStorageTestFixture @@ -86,7 +86,7 @@ all_ids.append(obj_id) all_ids.sort() - ids = list(self.storage.iter_from(b"\x00" * (ID_HASH_LENGTH // 2))) + ids = list(self.storage.iter_from(b"\x00" * ID_DIGEST_LENGTH)) self.assertEqual(len(ids), len(all_ids)) self.assertEqual(ids, all_ids)