What’s really happening when you add a file to IPFS?

From raw data to Merkle DAGs and a few steps in between

Carson Farmer
Aug 28, 2018 · 10 min read
Photo by Johannes Plenio on Unsplash

Fingerprinting

From raw image to cryptographic digest to content id (multihash).

Multihashing

Merkle DAG ➞ IPLD

Large files are chunked, hashed, and organized into an IPLD (Merkle DAG object).

Linked Data

Learning by doing

ipfs object get QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ | jq
{
  "Links": [
    {
      "Name": "cat.jpg",
      "Hash": "Qmd286K6pohQcTKYqnS1YhWrCiS4gz7Xi34sdwMe9USZ7u",
      "Size": 443362
    }
  ],
  "Data": "\b\u0001"
}
ipfs object get Qmd286K6pohQcTKYqnS1YhWrCiS4gz7Xi34sdwMe9USZ7u | jq
{
  "Links": [
    {
      "Name": "",
      "Hash": "QmPEKipMh6LsXzvtLxunSPP7ZsBM8y9xQ2SQQwBXy5UY6e",
      "Size": 262158
    },
    {
      "Name": "",
      "Hash": "QmT8onRUfPgvkoPMdMvCHPYxh98iKCfFkBYM1ufYpnkHJn",
      "Size": 181100
    }
  ],
  "Data": "\b\u0002\u0018ކ\u001b ��\u0010 ކ\u000b"
}
test_dir/
├── bigfile.js
├── *hello.txt
└── my_dir
    ├── *my_file.txt
    └── *testing.txt
ipfs add -r test_dir/
Graph of directory structure, originally from ConsenSys blog.
ipfs cat QmWNj1pTSjbauDHpdyg5HQ26vYcNWnubg1JehmwAE9NnU9 > cosmos.jpg
hash=`ipfs add -q cosmos.jpg`
echo $hash
QmWNj1pTSjbauDHpdyg5HQ26vYcNWnubg1JehmwAE9NnU9
ipfs ls -v $hash
Hash                                           Size   Name
QmPHPs1P3JaWi53q5qqiNauPhiTqa3S1mbszcVPHKGNWRh 262158 
QmPCuqUTNb21VDqtp5b8VsNzKEMtUsZCCVsEUBrjhERRSR 262158 
QmS7zrNSHEt5GpcaKrwdbnv1nckBreUxWnLaV4qivjaNr3 262158 
QmQQhY1syuqo9Sq6wLFAupHBEeqfB8jNnzYUSgZGARJrYa 76151
ipfs cat \
QmPHPs1P3JaWi53q5qqiNauPhiTqa3S1mbszcVPHKGNWRh \
QmPCuqUTNb21VDqtp5b8VsNzKEMtUsZCCVsEUBrjhERRSR \
QmS7zrNSHEt5GpcaKrwdbnv1nckBreUxWnLaV4qivjaNr3 \
QmQQhY1syuqo9Sq6wLFAupHBEeqfB8jNnzYUSgZGARJrYa \
> cat-cosmos.jpg
open cat-cosmos.jpg
ipfs refs $hash | ipfs cat > test.jpg ; open test.jpg

Recap

Textile

Building new digital experiences by focusing on user privacy, openness, and decentralization. Makers of https://www.textile.photos/

855

855 claps
Carson Farmer

Written by

Works at Textile.io. Former prof, turned dweb professional. Writes about ipfs, textile, dweb, decentralization, etc.

Textile

Textile

Building new digital experiences by focusing on user privacy, openness, and decentralization. Makers of https://www.textile.photos/