Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/backends/libcloud.py
Show First 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | def __len__(self): | ||||
performance applies. | performance applies. | ||||
Returns: | Returns: | ||||
number of objects contained in the storage. | number of objects contained in the storage. | ||||
""" | """ | ||||
return sum(1 for i in self) | return sum(1 for i in self) | ||||
def add(self, content: bytes, obj_id: ObjId, check_presence: bool = True) -> ObjId: | def add(self, content: bytes, obj_id: ObjId, check_presence: bool = True) -> None: | ||||
if check_presence and obj_id in self: | if check_presence and obj_id in self: | ||||
return obj_id | return | ||||
self._put_object(content, obj_id) | self._put_object(content, obj_id) | ||||
return obj_id | |||||
def restore(self, content: bytes, obj_id: ObjId): | def restore(self, content: bytes, obj_id: ObjId) -> None: | ||||
return self.add(content, obj_id, check_presence=False) | return self.add(content, obj_id, check_presence=False) | ||||
def get(self, obj_id: ObjId) -> bytes: | def get(self, obj_id: ObjId) -> bytes: | ||||
obj = b"".join(self._get_object(obj_id).as_stream()) | obj = b"".join(self._get_object(obj_id).as_stream()) | ||||
d = decompressors[self.compression]() | d = decompressors[self.compression]() | ||||
ret = d.decompress(obj) | ret = d.decompress(obj) | ||||
if d.unused_data: | if d.unused_data: | ||||
hex_obj_id = hashutil.hash_to_hex(obj_id) | hex_obj_id = hashutil.hash_to_hex(obj_id) | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |