| 152 | self.direct_items = 0 |
| 153 | |
| 154 | def get(self, inode): |
| 155 | offset = inode - self.offset |
| 156 | if offset < 0: |
| 157 | raise ValueError("ItemCache.get() called with an invalid inode number") |
| 158 | if self.meta[offset] == ord(b"I"): |
| 159 | _, chunk_id_relative_offset, chunk_offset = self.indirect_entry_struct.unpack_from(self.meta, offset) |
| 160 | chunk_id_offset = offset - chunk_id_relative_offset |
| 161 | # bytearray slices are bytearrays as well, explicitly convert to bytes() |
| 162 | chunk_id = bytes(self.meta[chunk_id_offset : chunk_id_offset + 32]) |
| 163 | chunk = self.chunks.get(chunk_id) |
| 164 | if not chunk: |
| 165 | csize, chunk = next(self.decrypted_repository.get_many([chunk_id])) |
| 166 | self.chunks[chunk_id] = chunk |
| 167 | data = memoryview(chunk)[chunk_offset:] |
| 168 | unpacker = msgpack.Unpacker() |
| 169 | unpacker.feed(data) |
| 170 | return Item(internal_dict=next(unpacker)) |
| 171 | elif self.meta[offset] == ord(b"S"): |
| 172 | fd_offset = int.from_bytes(self.meta[offset + 1 : offset + 9], "little") |
| 173 | self.fd.seek(fd_offset, io.SEEK_SET) |
| 174 | return Item(internal_dict=next(msgpack.Unpacker(self.fd, read_size=1024))) |
| 175 | else: |
| 176 | raise ValueError("Invalid entry type in self.meta") |
| 177 | |
| 178 | def iter_archive_items(self, archive_item_ids, filter=None): |
| 179 | unpacker = msgpack.Unpacker() |