| 450 | return result |
| 451 | |
| 452 | def get(self, id, read_data=True, raise_missing=True): |
| 453 | self._lock_refresh() |
| 454 | id_hex = bin_to_hex(id) |
| 455 | key = "data/" + id_hex |
| 456 | try: |
| 457 | if read_data: |
| 458 | # read everything |
| 459 | return self.store.load(key) |
| 460 | else: |
| 461 | # RepoObj layout supports separately encrypted metadata and data. |
| 462 | # We return enough bytes so the client can decrypt the metadata. |
| 463 | hdr_size = RepoObj.obj_header.size |
| 464 | extra_size = 1024 - hdr_size # load a bit more, 1024b, reduces round trips |
| 465 | obj = self.store.load(key, size=hdr_size + extra_size) |
| 466 | hdr = obj[0:hdr_size] |
| 467 | if len(hdr) != hdr_size: |
| 468 | raise IntegrityError(f"Object too small [id {id_hex}]: expected {hdr_size}, got {len(hdr)} bytes") |
| 469 | meta_size = RepoObj.obj_header.unpack(hdr)[0] |
| 470 | if meta_size > extra_size: |
| 471 | # we did not get enough, need to load more, but not all. |
| 472 | # this should be rare, as chunk metadata is rather small usually. |
| 473 | obj = self.store.load(key, size=hdr_size + meta_size) |
| 474 | meta = obj[hdr_size : hdr_size + meta_size] |
| 475 | if len(meta) != meta_size: |
| 476 | raise IntegrityError(f"Object too small [id {id_hex}]: expected {meta_size}, got {len(meta)} bytes") |
| 477 | return hdr + meta |
| 478 | except StoreObjectNotFound: |
| 479 | if raise_missing: |
| 480 | raise self.ObjectNotFound(id, str(self._location)) from None |
| 481 | else: |
| 482 | return None |
| 483 | |
| 484 | def get_many(self, ids, read_data=True, is_preloaded=False, raise_missing=True): |
| 485 | for id_ in ids: |