I want to initalize a fsspec
filesystem based on a URL - both the protocol and the root directory.
E.g. I could create a filesystem from gcs://my-bucket/prefix
that would use my-bucket
on GCS, or file:///tmp/test
that would use the /tmp/test
directory in the local filesystem.
It can be done easily with following 2-liner:
from fsspec.core import url_to_fs
from fsspec.implementations.dirfs import DirFileSystem
URL = 'file:///tmp/test'
root_fs, root_path = url_to_fs(URL)
fs = DirFileSystem(root_path, root_fs)
fs.open('foo') # This opens /tmp/test/foo if URL was file:///tmp/test
but it feels like there should be an API for that in fsspec directly.
Is there?