|
2 | 2 |
|
3 | 3 | import importlib.util |
4 | 4 | import json |
| 5 | +from asyncio import gather |
5 | 6 | from pathlib import Path |
6 | 7 | from typing import TYPE_CHECKING, Any, Literal, Self, TypeAlias |
7 | 8 |
|
@@ -163,6 +164,35 @@ async def get( |
163 | 164 | prototype = default_buffer_prototype() |
164 | 165 | return await self.store.get(self.path, prototype=prototype, byte_range=byte_range) |
165 | 166 |
|
| 167 | + async def get_many_ordered( |
| 168 | + self, |
| 169 | + *path_components: str, |
| 170 | + prototype: BufferPrototype | None = None, |
| 171 | + byte_range: ByteRequest | None = None, |
| 172 | + ) -> tuple[Buffer | None, ...]: |
| 173 | + """ |
| 174 | + Read multiple bytes from the store in order of the provided path_components. |
| 175 | +
|
| 176 | + Parameters |
| 177 | + ---------- |
| 178 | + path_components : str |
| 179 | + Components to append to the store path. |
| 180 | + prototype : BufferPrototype, optional |
| 181 | + The buffer prototype to use when reading the bytes. |
| 182 | + byte_range : ByteRequest, optional |
| 183 | + The range of bytes to read. |
| 184 | +
|
| 185 | + Returns |
| 186 | + ------- |
| 187 | + tuple[Buffer | None, ...] |
| 188 | + A tuple of buffers read from the store, in the order of the provided path_components. |
| 189 | + """ |
| 190 | + if prototype is None: |
| 191 | + prototype = default_buffer_prototype() |
| 192 | + |
| 193 | + tasks = [(self / component).path for component in path_components] |
| 194 | + return await self.store._get_many_ordered([(task, prototype, byte_range) for task in tasks]) |
| 195 | + |
166 | 196 | async def set(self, value: Buffer, byte_range: ByteRequest | None = None) -> None: |
167 | 197 | """ |
168 | 198 | Write bytes to the store. |
@@ -263,6 +293,10 @@ def __eq__(self, other: object) -> bool: |
263 | 293 | pass |
264 | 294 | return False |
265 | 295 |
|
| 296 | + async def _is_concurrency_save(self): |
| 297 | + fs = getattr(self.store, "fs", None) |
| 298 | + return getattr(fs, "asynchronous", True) |
| 299 | + |
266 | 300 |
|
267 | 301 | StoreLike: TypeAlias = Store | StorePath | FSMap | Path | str | dict[str, Buffer] |
268 | 302 |
|
|
0 commit comments