Skip to content

Commit 4878f49

Browse files
committed
fixup: remove CAR handling (for now)
1 parent 857914b commit 4878f49

File tree

3 files changed

+9
-148
lines changed

3 files changed

+9
-148
lines changed

ipfsspec/async_ipfs.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from fsspec.exceptions import FSTimeoutError
1414

1515
from multiformats import CID, multicodec
16-
from .car import read_car
1716
from . import unixfsv1
1817

1918
import logging
@@ -121,24 +120,23 @@ async def cat(self, path, session):
121120
return await res.read()
122121

123122
async def ls(self, path, session, detail=False):
124-
res = await self.get(path, session, headers={"Accept": "application/vnd.ipld.car"}, params={"format": "car", "dag-scope": "entity"})
123+
res = await self.get(path, session, headers={"Accept": "application/vnd.ipld.raw"}, params={"format": "raw"})
125124
self._raise_not_found_for_status(res, path)
126125
resdata = await res.read()
127-
root = CID.decode(res.headers["X-Ipfs-Roots"].split(",")[-1])
128-
assert root.codec == DagPbCodec, "this is not a directory"
129-
_, blocks = read_car(resdata) # roots should be ignored by https://specs.ipfs.tech/http-gateways/trustless-gateway/
130-
blocks = {cid: data for cid, data, _ in blocks}
131-
root_block = unixfsv1.PBNode.loads(blocks[root])
132-
root_data = unixfsv1.Data.loads(root_block.Data)
133-
if root_data.Type != unixfsv1.DataType.Directory:
126+
cid = CID.decode(res.headers["X-Ipfs-Roots"].split(",")[-1])
127+
assert cid.codec == DagPbCodec, "this is not a directory"
128+
node = unixfsv1.PBNode.loads(resdata)
129+
data = unixfsv1.Data.loads(node.Data)
130+
if data.Type != unixfsv1.DataType.Directory:
131+
# TODO: we might need support for HAMTShard here (for large directories)
134132
raise ValueError(f"The path '{path}' is not a directory")
135133

136134
if detail:
137135
return await asyncio.gather(*(
138136
self.info(path + "/" + link.Name, session)
139-
for link in root_block.Links))
137+
for link in node.Links))
140138
else:
141-
return [path + "/" + link.Name for link in root_block.Links]
139+
return [path + "/" + link.Name for link in node.Links]
142140

143141
def _raise_not_found_for_status(self, response, url):
144142
"""

ipfsspec/car.py

Lines changed: 0 additions & 116 deletions
This file was deleted.

ipfsspec/utils.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)