Skip to content

Commit 4e47d60

Browse files
committed
second workaround for suffix request
1 parent bc9b37e commit 4e47d60

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/zarr/storage/_obstore.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,25 @@ async def get(
106106
)
107107
return prototype.buffer.from_bytes(await resp.bytes_async()) # type: ignore[arg-type]
108108
elif isinstance(byte_range, SuffixByteRequest):
109-
resp = await obs.get_async(
110-
self.store, key, options={"range": {"suffix": byte_range.suffix}}
111-
)
112-
return prototype.buffer.from_bytes(await resp.bytes_async()) # type: ignore[arg-type]
109+
# some object stores (Azure) don't support suffix requests. In this
110+
# case, our workaround is to first get the length of the object and then
111+
# manually request the byte range at the end.
112+
try:
113+
resp = await obs.get_async(
114+
self.store, key, options={"range": {"suffix": byte_range.suffix}}
115+
)
116+
return prototype.buffer.from_bytes(await resp.bytes_async()) # type: ignore[arg-type]
117+
except obs.exceptions.NotSupportedError:
118+
head_resp = await obs.head_async(self.store, key)
119+
file_size = head_resp["size"]
120+
suffix_len = byte_range.suffix
121+
buffer = await obs.get_range_async(
122+
self.store,
123+
key,
124+
start=file_size - suffix_len,
125+
length=suffix_len,
126+
)
127+
return prototype.buffer.from_bytes(buffer) # type: ignore[arg-type]
113128
else:
114129
raise ValueError(f"Unexpected byte_range, got {byte_range}")
115130
except _ALLOWED_EXCEPTIONS:

0 commit comments

Comments
 (0)