Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix: report correct size for raw dag nodes #1591

Merged
merged 2 commits into from
Sep 27, 2018
Merged

Conversation

achingbrain
Copy link
Member

If you specify cidVersion: 0, for go compatibility you will have raw leaf nodes. If your data fits in one dag node, the root node will be a raw node for the same reason, and ipfs.object.get will return a buffer.

This PR inspects the returned node to see if it's a buffer, if it is, use the length property, otherwise use the DAGNode size property.

Fixes #1585

If you specify `cidVersion: 0`, for go compatibility you will have raw leaf nodes.
If your data fits in one dag node, the root node will be a raw node for the same
reason, and `ipfs.object.get` will return a buffer.

This PR inspects the returned node to see if it's a buffer, if it is, use the
`length` property, otherwise use the DAGNode `size` property.

Fixes #1585
@ghost ghost assigned achingbrain Sep 25, 2018
@ghost ghost added the status/in-progress In progress label Sep 25, 2018
expect(err).to.not.exist()
expect(files.length).to.equal(1)
expect(files[0].hash).to.equal('zdj7WcDSFNSsZkdkbpSDGeLsBtHbYKyvPQsaw6PpeeYdGqoAx')
expect(files[0].size).to.equal(11)
Copy link
Member Author

@achingbrain achingbrain Sep 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N.b. this is bigger than the input buffer due to the protobuf overhead. The other test uses raw nodes, so the data hasn't been wrapped in a protobuf.

@alanshaw alanshaw merged commit 549f2f6 into master Sep 27, 2018
@ghost ghost removed the status/in-progress In progress label Sep 27, 2018
@alanshaw alanshaw deleted the report-size-for-raw-nodes branch September 27, 2018 09:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants