@@ -212,19 +212,21 @@ def supports_listing(self) -> bool:
212212 # docstring inherited
213213 return True
214214
215- def list (self ) -> AsyncGenerator [str , None ]:
216- # docstring inherited
215+ async def _list (self , prefix : str | None = None ) -> AsyncGenerator [ObjectMeta , None ]:
217216 import obstore as obs
218217
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
221222
222- def list_prefix (self , prefix : str ) -> AsyncGenerator [str , None ]:
223+ def list (self ) -> AsyncGenerator [str , None ]:
223224 # docstring inherited
224- import obstore as obs
225+ return ( obj [ "path" ] async for obj in self . _list ())
225226
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 ))
228230
229231 def list_dir (self , prefix : str ) -> AsyncGenerator [str , None ]:
230232 # docstring inherited
@@ -233,21 +235,21 @@ def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
233235 coroutine = obs .list_with_delimiter_async (self .store , prefix = prefix )
234236 return _transform_list_dir (coroutine , prefix )
235237
238+ async def getsize (self , key : str ) -> int :
239+ # docstring inherited
240+ import obstore as obs
236241
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 )
246249
247250
248251async 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
251253) -> AsyncGenerator [str , None ]:
252254 """
253255 Transform the result of list_with_delimiter into an async generator of paths.
0 commit comments