|
13 | 13 | from fsspec.exceptions import FSTimeoutError
|
14 | 14 |
|
15 | 15 | from multiformats import CID, multicodec
|
16 |
| -from .car import read_car |
17 | 16 | from . import unixfsv1
|
18 | 17 |
|
19 | 18 | import logging
|
@@ -121,24 +120,23 @@ async def cat(self, path, session):
|
121 | 120 | return await res.read()
|
122 | 121 |
|
123 | 122 | 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"}) |
125 | 124 | self._raise_not_found_for_status(res, path)
|
126 | 125 | 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) |
134 | 132 | raise ValueError(f"The path '{path}' is not a directory")
|
135 | 133 |
|
136 | 134 | if detail:
|
137 | 135 | return await asyncio.gather(*(
|
138 | 136 | self.info(path + "/" + link.Name, session)
|
139 |
| - for link in root_block.Links)) |
| 137 | + for link in node.Links)) |
140 | 138 | else:
|
141 |
| - return [path + "/" + link.Name for link in root_block.Links] |
| 139 | + return [path + "/" + link.Name for link in node.Links] |
142 | 140 |
|
143 | 141 | def _raise_not_found_for_status(self, response, url):
|
144 | 142 | """
|
|
0 commit comments