/api/v0/dag/export partial download

Thanks for exposing /api/v0/dag/export on public gateways! This is game-changer for me :+1:

However my project (DAppNode) needs to download just a few files from a directory. Is it possible to query /api/v0/dag/export and get a verifiable CAR stream but stopping at the first directory?

Otherwise, is there a client that can reliably calculate the hash of a UnixFS directory given it’s JSON structure? i.e. given

{
  "Links": [
    {
      "Name": "avatar.png",
      "Hash": "QmTfnrUdZWaMgr2Zi1h1Z7zS5CbYtQZRs72yqKZQHj5fxT",
      "Size": 23107
    },
    {
      "Name": "dappnode_package.json",
      "Hash": "QmTRKT4oBef93Xdyvm2VRoPvhRN2HnUPvHuJ9PpSpEjdYw",
      "Size": 1645
    },
  ],
  "Data": "\b\u0001"
}

For context, I get a hash from a trusted source (a blockchain) that points to a UnixFS directory (assume the example above). Then I need to trustlessly download only the dappnode_package.json file.

Resolve first, then do dag-export:

curl 'https://ipfs.io/api/v0/resolve?arg=/ipfs/<your_cid>/<yourpath>'

Then use the resulting CID in the response as argument for dag/export.

Thanks for replying @hector but I think I didn’t why didn’t understood each other.

Given a CID that points to a UnixFS directory I want to get the list of files in that directory without downloading any, but verifying that the files list hash to the provided CID.

Ah, you can do block/get and decode the protobuf to get the list. The block/get output should directly hash to the CID, for small-enough directories.

Thanks! Is there JS client code to hash content and compute CIDs without interaction with a full client?

I guess GitHub - multiformats/js-cid: CID implementation in JavaScript