| 237 | return len(self.files) |
| 238 | |
| 239 | def __getitem__(self, key): |
| 240 | try: |
| 241 | key = self._files[key] |
| 242 | except KeyError: |
| 243 | raise KeyError(f"{key} is not a file in the archive") from None |
| 244 | else: |
| 245 | with self.zip.open(key) as bytes: |
| 246 | magic = bytes.read(len(format.MAGIC_PREFIX)) |
| 247 | bytes.seek(0) |
| 248 | if magic == format.MAGIC_PREFIX: |
| 249 | # FIXME: This seems like it will copy strings around |
| 250 | # more than is strictly necessary. The zipfile |
| 251 | # will read the string and then |
| 252 | # the format.read_array will copy the string |
| 253 | # to another place in memory. |
| 254 | # It would be better if the zipfile could read |
| 255 | # (or at least uncompress) the data |
| 256 | # directly into the array memory. |
| 257 | return format.read_array( |
| 258 | bytes, |
| 259 | allow_pickle=self.allow_pickle, |
| 260 | pickle_kwargs=self.pickle_kwargs, |
| 261 | max_header_size=self.max_header_size |
| 262 | ) |
| 263 | else: |
| 264 | return bytes.read() |
| 265 | |
| 266 | def __contains__(self, key): |
| 267 | return (key in self._files) |