|
7 | 7 | from zarr.abc.store import ByteRequest, Store |
8 | 8 | from zarr.core.buffer import Buffer, default_buffer_prototype |
9 | 9 | from zarr.core.common import ZARR_JSON, ZARRAY_JSON, ZGROUP_JSON, AccessModeLiteral, ZarrFormat |
| 10 | +from zarr.core.sync import sync |
10 | 11 | from zarr.errors import ContainsArrayAndGroupError, ContainsArrayError, ContainsGroupError |
11 | 12 | from zarr.storage._local import LocalStore |
12 | 13 | from zarr.storage._memory import MemoryStore |
13 | 14 | from zarr.storage._utils import normalize_path |
14 | 15 |
|
15 | 16 | if TYPE_CHECKING: |
| 17 | + from zarr import Array, Group |
16 | 18 | from zarr.core.buffer import BufferPrototype |
17 | 19 |
|
18 | 20 |
|
@@ -505,3 +507,26 @@ async def contains_group(store_path: StorePath, zarr_format: ZarrFormat) -> bool |
505 | 507 | return await (store_path / ZGROUP_JSON).exists() |
506 | 508 | msg = f"Invalid zarr_format provided. Got {zarr_format}, expected 2 or 3" # type: ignore[unreachable] |
507 | 509 | raise ValueError(msg) |
| 510 | + |
| 511 | + |
| 512 | +def get_node(store: Store, path: str, zarr_format: ZarrFormat) -> Array | Group: |
| 513 | + """ |
| 514 | + Get an Array or Group from a path in a Store. |
| 515 | +
|
| 516 | + Parameters |
| 517 | + ---------- |
| 518 | + store : Store |
| 519 | + The store-like object to read from. |
| 520 | + path : str |
| 521 | + The path to the node to read. |
| 522 | + zarr_format : {2, 3} |
| 523 | + The zarr format of the node to read. |
| 524 | +
|
| 525 | + Returns |
| 526 | + ------- |
| 527 | + Array | Group |
| 528 | + """ |
| 529 | + from zarr.core.group import _parse_async_node |
| 530 | + from zarr.core.group import get_node as get_node_async |
| 531 | + |
| 532 | + return _parse_async_node(sync(get_node_async(store=store, path=path, zarr_format=zarr_format))) |
0 commit comments