Reputation: 1007
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.
Upvotes: 4
Views: 900
Reputation: 555
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
)Upvotes: 5