I’m currently working on a program synchronizing local files to IPFS and I have trouble getting the same file size from IPFS files as from local files.
Here in this list of examples I’m adding increasingly bigger files to IPFS and each time the file difference (local size vs IPFS size) increases progressively.
# Raw data file size of 0b
$ ipfs object stat $(dd if=/dev/random count=0 bs=1 status=none | ipfs add --pin=false -Q)
NumLinks: 0
BlockSize: 6
LinksSize: 2
DataSize: 4
CumulativeSize: 6
# Diff size => 6b
# Raw data file size of 10b
$ ipfs object stat $(dd if=/dev/random count=10 bs=1 status=none | ipfs add --pin=false -Q)
NumLinks: 0
BlockSize: 18
LinksSize: 2
DataSize: 16
CumulativeSize: 18
# Diff size => 8b
# Raw data file size of 1kb
$ ipfs object stat $(dd if=/dev/random count=1000 bs=1 status=none | ipfs add --pin=false -Q)
NumLinks: 0
BlockSize: 1011
LinksSize: 3
DataSize: 1008
CumulativeSize: 1011
# Diff size => 11b
# Raw data file size of 100kb
$ ipfs object stat $(dd if=/dev/random count=100000 bs=1 status=none | ipfs add --pin=false -Q)
NumLinks: 0
BlockSize: 100014
LinksSize: 4
DataSize: 100010
CumulativeSize: 100014
# Diff size => 14b
# Raw data file size of 1mb
$ ipfs object stat $(dd if=/dev/random count=1000000 bs=1 status=none | ipfs add --pin=false -Q)
NumLinks: 4
BlockSize: 200
LinksSize: 178
DataSize: 22
CumulativeSize: 1000256
# Diff size => 256b
I understand that for the last example, the file chunker come into play and further increases the size difference but I don’t see where the size difference comes from in the other examples.
Is there any formula I can use to convert the CumulativeSize of IPFS object to get the original local file size?
Alternatively you could catch the X-Content-Length http header from /api/v0/cat.
I’m not sure if your node need to fetch the entire object for this to work tough.