I have been using IPFS at the IPLD level for a while, but now I have to deal with files, i.e. UnixfsV1. I need to do some sanity checks on CIDs passed into my code, such as checking if it’s a file or a directory, and checking the file size before downloading a potentially huge stream of bytes.
Therefore I am looking for a way to obtain metadata given a dag-pb CID, and in particular the DataType and filesize fields of the ProtoBuf record, using the HTTP API. In principle, I can use the block API ( /api/v0/block/get) to obtain the raw data and decode the ProtoBuf myself, but I would prefer to avoid going into such low-level details.
ipfs object operates on the merkledag-pb layer, which wraps the unixfs-pb.
1677 is the actual file size as reported by a field in the unixfs-protobuf (which ls uses).
1685 is the DataSize in the block, which is the [full_blocksize - links size] (the full merkledag-pb block being 1688 ytes). So this is the size of the unixfs protobuf inside the pb-merkledag block.
Instead, if we want answers from the unixfs layer we need to use ipfs files:
In the last one, Size is the actual file size as it would be on disk. CumulativeSize corresponds to that of ipfs object stat, that is, the actual size the dag under that CID takes on IPFS.