Skip to content

Commit 453d8c5

Browse files
authored
Doc and info for dataFS (#1421)
1 parent 4f70f1b commit 453d8c5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

fsspec/implementations/data.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@ class DataFileSystem(AbstractFileSystem):
1818

1919
protocol = "data"
2020

21+
def __init__(self, **kwargs):
22+
"""No parameters for this filesystem"""
23+
super().__init__(**kwargs)
24+
2125
def cat_file(self, path, start=None, end=None, **kwargs):
2226
pref, data = path.split(",", 1)
2327
if pref.endswith("base64"):
2428
return base64.b64decode(data)[start:end]
2529
return unquote(data).encode()[start:end]
2630

31+
def info(self, path, **kwargs):
32+
pref, name = path.split(",", 1)
33+
data = self.cat_file(path)
34+
mime = pref.split(":", 1)[1].split(";", 1)[0]
35+
return {"name": name, "size": len(data), "type": "file", "mimetype": mime}
36+
2737
def _open(
2838
self,
2939
path,

fsspec/implementations/tests/test_data.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@ def test_1():
77

88
with fsspec.open("data:,Hello%2C%20World%21") as f:
99
assert f.read() == b"Hello, World!"
10+
11+
12+
def test_info():
13+
fs = fsspec.filesystem("data")
14+
info = fs.info("data:text/html,%3Ch1%3EHello%2C%20World%21%3C%2Fh1%3E")
15+
assert info == {
16+
"name": "%3Ch1%3EHello%2C%20World%21%3C%2Fh1%3E",
17+
"size": 22,
18+
"type": "file",
19+
"mimetype": "text/html",
20+
}

0 commit comments

Comments
 (0)