diff --git a/kerchunk/sync_wrapper.py b/kerchunk/sync_wrapper.py new file mode 100644 index 00000000..76b40f28 --- /dev/null +++ b/kerchunk/sync_wrapper.py @@ -0,0 +1,21 @@ +import inspect +from fsspec.asyn import AsyncFileSystem + + +class SynchronousWrapper(AsyncFileSystem): + """If the calling code requires an async filesystem, but you have sync""" + + def __init__(self, fs, **kw): + self.fs = fs + super().__init__(**kw) + + def __getattribute__(self, item): + fs = object.__getattribute__(self, "fs") + if inspect.iscoroutinefunction(getattr(AsyncFileSystem, item)): + + async def f(*args, **kwargs): + return getattr(fs, item.lstrip("_"))(*args, **kwargs) + + return f + else: + return getattr(fs, item)