|
| 1 | +from typing import Any |
| 2 | + |
| 3 | +from fsspec.asyn import AsyncFileSystem |
| 4 | + |
| 5 | +from lakefs_spec import LakeFSFileSystem, LakeFSTransaction |
| 6 | +from lakefs_spec.util import async_wrapper |
| 7 | + |
| 8 | + |
| 9 | +class AsyncLakeFSFileSystem(AsyncFileSystem): |
| 10 | + """Asynchronous wrapper around a LakeFSFileSystem""" |
| 11 | + |
| 12 | + protocol = "lakefs" |
| 13 | + transaction_type = LakeFSTransaction |
| 14 | + |
| 15 | + def __init__( |
| 16 | + self, |
| 17 | + host: str | None = None, |
| 18 | + username: str | None = None, |
| 19 | + password: str | None = None, |
| 20 | + api_key: str | None = None, |
| 21 | + api_key_prefix: str | None = None, |
| 22 | + access_token: str | None = None, |
| 23 | + verify_ssl: bool = True, |
| 24 | + ssl_ca_cert: str | None = None, |
| 25 | + proxy: str | None = None, |
| 26 | + create_branch_ok: bool = True, |
| 27 | + source_branch: str = "main", |
| 28 | + **storage_options: Any, |
| 29 | + ): |
| 30 | + super().__init__(**storage_options) |
| 31 | + |
| 32 | + self._sync_fs = LakeFSFileSystem( |
| 33 | + host, |
| 34 | + username, |
| 35 | + password, |
| 36 | + api_key, |
| 37 | + api_key_prefix, |
| 38 | + access_token, |
| 39 | + verify_ssl, |
| 40 | + ssl_ca_cert, |
| 41 | + proxy, |
| 42 | + create_branch_ok, |
| 43 | + source_branch, |
| 44 | + **storage_options, |
| 45 | + ) |
| 46 | + |
| 47 | + async def _rm_file(self, path, **kwargs): |
| 48 | + return async_wrapper(self._sync_fs.rm_file)(path) |
| 49 | + |
| 50 | + async def _cp_file(self, path1, path2, **kwargs): |
| 51 | + return async_wrapper(self._sync_fs.cp_file)(path1, path2, **kwargs) |
| 52 | + |
| 53 | + async def _pipe_file(self, path, value, **kwargs): |
| 54 | + return async_wrapper(self._sync_fs.pipe_file)(path, value, **kwargs) |
| 55 | + |
| 56 | + async def _cat_file(self, path, start=None, end=None, **kwargs): |
| 57 | + return async_wrapper(self._sync_fs.cat_file)(path, start, end, **kwargs) |
| 58 | + |
| 59 | + async def _put_file(self, lpath, rpath, **kwargs): |
| 60 | + return async_wrapper(self._sync_fs.put_file)(lpath, rpath, **kwargs) |
| 61 | + |
| 62 | + async def _get_file(self, rpath, lpath, **kwargs): |
| 63 | + return async_wrapper(self._sync_fs.get_file)(rpath, lpath, **kwargs) |
| 64 | + |
| 65 | + async def _info(self, path, **kwargs): |
| 66 | + return async_wrapper(self._sync_fs.info)(path, **kwargs) |
| 67 | + |
| 68 | + async def _ls(self, path, detail=True, **kwargs): |
| 69 | + return async_wrapper(self._sync_fs.ls)(path, detail, **kwargs) |
0 commit comments