Hey @tuan3w, the idea of the files API (you might also see it referred to as āMFSā or Mutable FileSystem) is generally to make it easier to edit and organize files in IPFS. Since nothing can be changed after itās added to IPFS (or: changing a file/directory changeās its hash, which basically means youāre making a new file), doing something that might simple on your hard drive, like renaming a file, can be pretty complicated in IPFS.
For example, if you had a directory structure like:
/documents
/ipfs-introduction
- overview.txt
- use-cases.txt
And you renamed overview.txt
to introduction.txt
, youād have to:
- Make a copy of the
ipfs-introduction
directory and change the name of the file in it.
- Add the new directory to IPFS.
- Make a copy of the
documents
directory and change the hash for the ipfs-introduction
directory in it to point to the new one.
- Add that new directory to IPFS.
- Get the new hash for
documents
so you can share it.
To make that easier, the files API gives you some basic Unix-style commands (cp
, ls
, mkdir
, mv
, rm
) to manipulate files. When you use them, IPFS takes care of managing all the different hashes and links that have to change. So, to do the above operation, you can just:
-
Move the file:
> ipfs files mv /documents/ipfs-introduction/overview.txt /documents/ipfs-introduction/introduction.txt
-
Get the hash:
> ipfs files stat /documents
Does that make sense? Hopefully that helps clarify some of your original questions:
ipfs files cp
doesnāt make a copy; it just adds a pointer to the hash of the file you are copying. So in your example, you added a pointer named greetings
in the IPFS object that represents the root directory whose value is /ipfs/Qmc4xcnns2rA4akaWfGdzdaN8My1ES6zh7yddYZ5mo7n2U
.
When we call some function like ipfs files mkdir
and ipfs files write
On the other hand, ipfs files write
adds the data to IPFS. Itās kind of like ipfs add [filename]
, except it doesnāt just add it to the IPFS network with a hash ā it also puts it in the MFS root directory with a nice name. After that, youāll have:
- The original file on your computerās filesystem
- A copy of the file in IPFS
- Two pointers to the file in IPFS: one as just a regular hash and one from MFS
does anyone can access to it or they have my private key?
Right now, the only way to access MFS content is through the files API. That means someone has to have access to your IPFS nodeās API in order to read. The API is normally private (only your computer can access it). You can change that, but I donāt recommend it.