ipfs.add和ipfs.dag.put有什么区别?
使用js-ipfs
lib,我正在努力寻找有关以下命令之间区别的良好信息:
> await ipfs.add('hello world',{cidVersion:1})
{
path: 'bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e',
cid: CID(bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e),
size: 11,
mode: undefined,
mtime: undefined
}
> await ipfs.dag.put('hello world')
CID(bafyreifg3qptriirganaf6ggmbdhclgzz7gncundvtsyrovyzqigm25jfe)
我的期望:CID会相同。
会欣赏任何指示。
Using the js-ipfs
lib, I'm struggling to find good information regarding the difference between the following commands:
> await ipfs.add('hello world',{cidVersion:1})
{
path: 'bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e',
cid: CID(bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e),
size: 11,
mode: undefined,
mtime: undefined
}
> await ipfs.dag.put('hello world')
CID(bafyreifg3qptriirganaf6ggmbdhclgzz7gncundvtsyrovyzqigm25jfe)
My expectation: CIDs would be the same.
Would appreciate any pointers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下基于 Kubo RPC,但 JS-IPFS 基于它,并且很可能做了类似的事情(唯一的区别可能是 Kubo 中的
dag put
默认情况下需要/需要 dag-json)ipfs dag put
允许您操作除文件和目录之外的 IPLD 数据结构。在 Kubo 中,此命令将假定输入为 dag-json 并将存储它作为二进制 dag-cbor。您可以在 https://cid.ipfs.tech 上比较生成的 CID – 在您的示例中:
ipfs add
创建了原始块(因为“hello world”适合单个块,不需要 dag-pb)ipfs dag
创建了 dag-cbor(因为这是默认值--存储编解码器
)Below is based on
ipfs add
anddag put
from Kubo RPC, but JS-IPFS was based on it and most likely does something similar (only difference may be thatdag put
in Kubo expects/requires dag-json by default)ipfs add
is for adding files and directories and representing them as UnixFS. It will chunk bigger files into smaller blocks and represent them as dag-pb or raw bytes (leaves).ipfs dag put
allows you to operate on IPLD data structures other than files and directories. In Kubo, this command will assume input to be dag-json and will store it as binary dag-cbor.You can compare produced CIDs at https://cid.ipfs.tech – in your example:
ipfs add
created raw block (because 'hello world' fits in a single block, no need for dag-pb)ipfs dag
created dag-cbor (because that is the default--store-codec
)