Konubinix' opinionated web of thoughts

Ipfs Dag Get and Ipfs Dag Put?

fleeting

If I understand correctly, files in ipfs are chunked into blocks and those blocks are linked using a merkle DAG protocol buffer based format called unixfs. Also, ipfs dag is used to manipulate those.

Yet, there is something strange that does not fit with this idea.

Say I add the “hello world” content in ipfs.

HASH="$(echo "hello world"|ipfs add --quieter --pin=false --cid-version=1)"
echo "${HASH}"
bafkreifjjcie6lypi6ny7amxnfftagclbuxndqonfipmb64f2km2devei4

This hash is actually representing a dag that points to the content of my file.

ipfs dag get "${HASH}"|jq -M
{
  "/": {
    "bytes": "aGVsbG8gd29ybGQK"
  }
}

Then, if I put the same content in ipfs, I should have the same dag

NEW_HASH="$(ipfs dag get "${HASH}"|ipfs dag put)"
echo "${NEW_HASH}"
bafyreihulmkyt4pmfstbd5tewf4re35y3xpr7ss2c36rqik4dlvl2pxw2a

See? The hash are different. And even worse, they lead to the same dag content.

ipfs dag get "${NEW_HASH}"|jq -M
{
  "/": {
    "bytes": "aGVsbG8gd29ybGQK"
  }
}

But, I can “read” one while the other is just some obscure block.

ipfs cat "${HASH}"
ipfs cat "${NEW_HASH}"
hello world
Error: unknown node type

Notes linking here