英文:
Initialize fsspec DirFileSystem from a URL
问题
我想要根据URL初始化一个fsspec
文件系统,包括协议和根目录。例如,我可以从gcs://my-bucket/prefix
创建一个使用GCS上的my-bucket
的文件系统,或者从file:///tmp/test
创建一个使用本地文件系统中的/tmp/test
目录的文件系统。
可以使用以下两行代码轻松完成:
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') # 如果URL是file:///tmp/test,这将打开/tmp/test/foo
但感觉在fsspec
中应该有一个直接的API来实现这一点。
有吗?
英文:
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?
答案1
得分: 2
A fix at https://github.com/fsspec/filesystem_spec/pull/1201 will enable this as requested. Your URL will be like "dir::protocol://path/to/mount".
英文:
A fix at https://github.com/fsspec/filesystem_spec/pull/1201 will enable this as requested. Your URL will be like "dir::protocol://path/to/mount".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论