diff --git a/src/dag-link/util.js b/src/dag-link/util.js index c845dd6..b51c7a3 100644 --- a/src/dag-link/util.js +++ b/src/dag-link/util.js @@ -4,9 +4,9 @@ const DAGLink = require('./index') function createDagLinkFromB58EncodedHash (link) { return new DAGLink( - link.name ? link.name : link.Name, - link.size ? link.size : link.Tsize, - link.hash || link.Hash || link.multihash || link.cid + link.Name || link.name || '', + link.Tsize || link.Size || link.size || 0, + link.Hash || link.hash || link.multihash || link.cid ) } diff --git a/test/dag-node-test.js b/test/dag-node-test.js index b97ed5e..2204fe9 100644 --- a/test/dag-node-test.js +++ b/test/dag-node-test.js @@ -443,5 +443,14 @@ module.exports = (repo) => { const deserializedObject = dagPB.util.deserialize(serializedObject) expect(deserialized.toJSON()).to.deep.equal(deserializedObject.toJSON()) }) + + it('creates links from objects with .Size properties', () => { + const node = DAGNode.create(Buffer.from('some data'), [{ + Hash: 'QmUxD5gZfKzm8UN4WaguAMAZjw2TzZ2ZUmcqm2qXPtais7', + Size: 9001 + }]) + + expect(node.Links[0].Tsize).to.eql(9001) + }) }) }