Links in IPLD implementation

Hello.
I’m looking at the implementation docs, specifically here https://github.com/ipld/js-ipld-dag-pb#daglinkcreatename-size-multihash-callback

When creating a link, a size parameter must be specified.
What is that size parameter? The documentation says nothing about what it is exactly.

Best,
Anton

Note: this only applies to DagPB. IPLD, in general, does not require that anyone specify a size.

The size is the size of the linked DAG. It’s the size of the linked object plus the size of it’s children, plus the size of it’s children’s children, etc. Alternatively, it’s the size of the linked object plus the sum of the size fields in the linked object’s Links array.

1 Like

why is that necessary? and why can’t that be calculated automatically?

In dagpb protobuf definition the size field is actually optional [1], and can be left out.

It is just a hint, so you don’t have to download whole file to view it’s size in a directory or seek() through it.

[1] - https://github.com/ipfs/go-ipfs/blob/master/merkledag/pb/merkledag.proto#L28

1 Like

Thank you very much everyone :slight_smile:

Nit: It can’t actually be used for seeking because it’s the size of the DAG, not the size of the file. Seekability is achieved through a filesize field and a blocksizes array in the unixfs protobuf. the Size field is just allows one calculate download progress/dag size.