@@ -212,19 +212,21 @@ def supports_listing(self) -> bool:
212
212
# docstring inherited
213
213
return True
214
214
215
- def list (self ) -> AsyncGenerator [str , None ]:
216
- # docstring inherited
215
+ async def _list (self , prefix : str | None = None ) -> AsyncGenerator [ObjectMeta , None ]:
217
216
import obstore as obs
218
217
219
- objects : ListStream [Sequence [ObjectMeta ]] = obs .list (self .store )
220
- return _transform_list (objects )
218
+ objects : ListStream [Sequence [ObjectMeta ]] = obs .list (self .store , prefix = prefix )
219
+ async for batch in objects :
220
+ for item in batch :
221
+ yield item
221
222
222
- def list_prefix (self , prefix : str ) -> AsyncGenerator [str , None ]:
223
+ def list (self ) -> AsyncGenerator [str , None ]:
223
224
# docstring inherited
224
- import obstore as obs
225
+ return ( obj [ "path" ] async for obj in self . _list ())
225
226
226
- objects : ListStream [Sequence [ObjectMeta ]] = obs .list (self .store , prefix = prefix )
227
- return _transform_list (objects )
227
+ def list_prefix (self , prefix : str ) -> AsyncGenerator [str , None ]:
228
+ # docstring inherited
229
+ return (obj ["path" ] async for obj in self ._list (prefix ))
228
230
229
231
def list_dir (self , prefix : str ) -> AsyncGenerator [str , None ]:
230
232
# docstring inherited
@@ -233,21 +235,21 @@ def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
233
235
coroutine = obs .list_with_delimiter_async (self .store , prefix = prefix )
234
236
return _transform_list_dir (coroutine , prefix )
235
237
238
+ async def getsize (self , key : str ) -> int :
239
+ # docstring inherited
240
+ import obstore as obs
236
241
237
- async def _transform_list (
238
- list_stream : ListStream [Sequence [ObjectMeta ]],
239
- ) -> AsyncGenerator [str , None ]:
240
- """
241
- Transform the result of list into an async generator of paths.
242
- """
243
- async for batch in list_stream :
244
- for item in batch :
245
- yield item ["path" ]
242
+ resp = await obs .head_async (self .store , key )
243
+ return resp ["size" ]
244
+
245
+ async def getsize_prefix (self , prefix : str ) -> int :
246
+ # docstring inherited
247
+ sizes = [obj ["size" ] async for obj in self ._list (prefix = prefix )]
248
+ return sum (sizes )
246
249
247
250
248
251
async def _transform_list_dir (
249
- list_result_coroutine : Coroutine [Any , Any , ListResult [Sequence [ObjectMeta ]]],
250
- prefix : str ,
252
+ list_result_coroutine : Coroutine [Any , Any , ListResult [Sequence [ObjectMeta ]]], prefix : str
251
253
) -> AsyncGenerator [str , None ]:
252
254
"""
253
255
Transform the result of list_with_delimiter into an async generator of paths.
0 commit comments