Skip to content

Commit 17d9f75

Browse files
committed
feat(storage): add private SupportsGetRanges protocol
1 parent 865baf0 commit 17d9f75

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

src/zarr/storage/_protocols.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# src/zarr/storage/_protocols.py
2+
from __future__ import annotations
3+
4+
from typing import TYPE_CHECKING, Protocol, runtime_checkable
5+
6+
if TYPE_CHECKING:
7+
from collections.abc import AsyncIterator, Iterable, Sequence
8+
9+
from zarr.abc.store import ByteRequest
10+
from zarr.core.buffer import Buffer, BufferPrototype
11+
12+
13+
@runtime_checkable
14+
class SupportsGetRanges(Protocol):
15+
"""Stores that satisfy this protocol can efficiently read many byte ranges
16+
from a single key in a single call, typically via coalescing and concurrent fetch.
17+
18+
Private / unstable. Shape may change before being made public.
19+
"""
20+
21+
def get_ranges(
22+
self,
23+
key: str,
24+
byte_ranges: Iterable[ByteRequest | None],
25+
*,
26+
prototype: BufferPrototype,
27+
) -> AsyncIterator[Sequence[tuple[int, Buffer | None]]]:
28+
"""Read many byte ranges from ``key``.
29+
30+
Each yield corresponds to one underlying I/O operation.
31+
32+
See :func:`zarr.core._coalesce.coalesced_get` for full semantics.
33+
"""
34+
...

0 commit comments

Comments
 (0)