This was originally found as a part of #1440 and https://github.com/ipfs/js-ipfs-http-response/pull/9
For some inputs ipfs.files.add with {cidVersion: 1} returns valid CID however size field is undefined. The problem does not occur if {cidVersion: 0} is used.
{ path: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
size: 20 }
{ path: 'zb2rhdTDKmCQD2a9x2TfLR61M3s7RmESzwV5mqgnakXQbm5gp',
hash: 'zb2rhdTDKmCQD2a9x2TfLR61M3s7RmESzwV5mqgnakXQbm5gp',
size: undefined }
Did not look into details, but I attach test case that illustrates the issue: js-ipfs-add-cidv1-missing-size-bug-repro.zip.
To run it: yarn && yarn test (or npm install && npm test).
Hope this helps.
@achingbrain do you have some time to look into this one? Looks like it might be a bug in unixfs-engine.
Sure, I'll take a look
Found the issue, see #1591
@lidel thanks so much for providing the failing test as an example. However even after the fix is merged it'll still fail because it asserts that the reported size of the file added with the v1 CID is greater than the input buffer - the default behaviour for v0 CIDs was to wrap all data in protobufs but for v1 it's to have it as a raw node (e.g. just a buffer), so the reported size will be the same as the input buffer. Just so you know...
Most helpful comment
Found the issue, see #1591
@lidel thanks so much for providing the failing test as an example. However even after the fix is merged it'll still fail because it asserts that the reported size of the file added with the v1 CID is greater than the input buffer - the default behaviour for v0 CIDs was to wrap all data in protobufs but for v1 it's to have it as a raw node (e.g. just a buffer), so the reported size will be the same as the input buffer. Just so you know...