Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/objstorage.py
Show All 16 Lines | |||||
ID_HASH_ALGO = "sha1" | ID_HASH_ALGO = "sha1" | ||||
ID_HEXDIGEST_LENGTH = 40 | ID_HEXDIGEST_LENGTH = 40 | ||||
"""Size in bytes of the hash hexadecimal representation.""" | """Size in bytes of the hash hexadecimal representation.""" | ||||
ID_DIGEST_LENGTH = 20 | ID_DIGEST_LENGTH = 20 | ||||
"""Size in bytes of the hash""" | """Size in bytes of the hash""" | ||||
DEFAULT_CHUNK_SIZE = 2 * 1024 * 1024 | |||||
"""Size in bytes of the streaming chunks""" | |||||
DEFAULT_LIMIT = 10000 | DEFAULT_LIMIT = 10000 | ||||
"""Default number of results of ``list_content``.""" | """Default number of results of ``list_content``.""" | ||||
def compute_hash(content): | def compute_hash(content): | ||||
"""Compute the content's hash. | """Compute the content's hash. | ||||
Args: | Args: | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | class ObjStorage(metaclass=abc.ABCMeta): | ||||
# Management methods | # Management methods | ||||
def get_random(self, batch_size): | def get_random(self, batch_size): | ||||
pass | pass | ||||
# Streaming methods | # Streaming methods | ||||
def add_stream(self, content_iter, obj_id, check_presence=True): | |||||
raise NotImplementedError | |||||
def get_stream(self, obj_id, chunk_size=DEFAULT_CHUNK_SIZE): | |||||
raise NotImplementedError | |||||
def list_content(self, last_obj_id=None, limit=DEFAULT_LIMIT): | def list_content(self, last_obj_id=None, limit=DEFAULT_LIMIT): | ||||
it = iter(self) | it = iter(self) | ||||
if last_obj_id: | if last_obj_id: | ||||
it = dropwhile(lambda x: x <= last_obj_id, it) | it = dropwhile(lambda x: x <= last_obj_id, it) | ||||
return islice(it, limit) | return islice(it, limit) |