ipfs.add和ipfs.dag.put有什么区别?

发布于 2025-01-18 06:53:56 字数 472 浏览 3 评论 0原文

使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木落 2025-01-25 06:53:56

以下基于 Kubo RPC,但 JS-IPFS 基于它,并且很可能做了类似的事情(唯一的区别可能是 Kubo 中的 dag put 默认情况下需要/需要 dag-json)

  • <代码>ipfs add 用于添加文件和目录并将它们表示为 UnixFS。它将较大的文件分成较小的块,并将它们表示为 dag-pb 或原始字节(叶)。
  • 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 and dag put from Kubo RPC, but JS-IPFS was based on it and most likely does something similar (only difference may be that dag 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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文