Kevvv
Kevvv

Reputation: 4023

Mutable File System vs Regular Files API in IPFS

What's the difference between Mutable File System's (MFS) read:

await ipfs.files.read('/some/stuff/success.txt')

and Regular Files API's cat:

await ifps.cat(someFile)

Is it the fact that the cat method first searches your own node for the file requested, and if it can't find it there, it will attempt to find it on the broader IPFS network?

Upvotes: 1

Views: 897

Answers (1)

Dietrich Ayala
Dietrich Ayala

Reputation: 941

The parameter for cat is an IPFS Path, not a file path. An IPFS Path is basically all the variations on a content identifier.

cat will fetch the data from the local repo if it exists there, or ask the network if it does not.

files.read accepts an MFS path, which is a file path for a file you've already added to your IPFS repo - as well as an IPFS Path or CID object. If you pass an MFS path, a file or directory at that path must already be in the local repo already or the API will not find anything.

The documentation for files.read:

https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#filesread

The documentation for cat:

https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#cat

A good tutorial on the Regular Files API is here:

https://proto.school/#/regular-files-api/04

And one for MFS and file.read:

https://proto.school/#/mutable-file-system/10

And a tutorial on CIDs (content identifiers) is here:

https://proto.school/#/data-structures/04

Upvotes: 2

Related Questions