-
Notifications
You must be signed in to change notification settings - Fork 24
Description
This function is a bit of a mess (not your mess, this is ancient stuff), there's also the fact that your fix for the 'object' check is going to avoid arrays now, so the bug was hiding issues that already exists.
We have this logic tested and used in js-multiformats, so maybe you could use that instead? if you import multiformats/block' then you could use links()on a block form of a decoded object, and that would cover any object type regardless of codec (the fact that this is dedicated to dag-cbor is a bit weird sinceobj` could be anything—probably a historical thing but the logic in here seems to differentiate dag-pb from everything else, which is the appropriate way to deal with dag-pb since it's legacy and everything else is newer).
See multiformats/js-multiformats@master/test/test-block.js#L45-L51 for this in action, it'll properly walk through the object and yield the links in the object along with the paths. You could wrap that in the additional stuff you need to get your size etc.
Alternatively, maybe steal some of the logic in there because we've worked on that one (and tree() to better handle all possible node types and iterate through them - bytes, null, arrays, CIDs, they all come with special cases which is annoying to have to reimplement and test for yourself. multiformats/js-multiformats@f2664fb/src/block.js#L49-L68
See https://github.com/ipfs/ipld-explorer-components/pull/330/files#r969207674