Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

feat: add util.cid options #66

Merged
merged 3 commits into from
Jun 25, 2018
Merged

feat: add util.cid options #66

merged 3 commits into from
Jun 25, 2018

Conversation

richardschneider
Copy link
Contributor

Copy link
Member

@vmx vmx left a comment

Choose a reason for hiding this comment

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

Thanks for adding the JSDoc comments.

src/util.js Outdated
* @returns {void}
*/
exports.cid = (dagNode, options, callback) => {
if (options instanceof Function) {
Copy link
Member

Choose a reason for hiding this comment

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

Searching through the existing IPFS/IPLD code base it seems that the preferred way for checking if something is a function is: if (typeof options !== 'function') {. My guess is that it is related to code minifiers. Please change it.

src/util.js Outdated
}
options = options || {}
const hashAlg = options.hashAlg || resolver.defaultHashAlg
const version = options.version || 1
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't work correctly. If options.version is set to 0, then version would become 1 as 0 evaluates to false.

Copy link
Member

@vmx vmx left a comment

Choose a reason for hiding this comment

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

I should've found that earlier. Can you please add tests for the error cases, when invalid options are passed in?

@richardschneider
Copy link
Contributor Author

The only error cases, that I can think of, are an invalid version or hash algorithm. Both cases should be handled by by underlaying software, cids and multihashing-async.

Copy link
Member

@vmx vmx left a comment

Choose a reason for hiding this comment

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

Good point. Often things are not handled correctly, but you are right, it should be handled by the underlying libraries. Could you have a quick look to see if they do handle it and if not open issues on those? If that's a too big ask, let me know and I'll check myself.

I'll also approve the other PRs where I mentioned the same thing.

@vmx
Copy link
Member

vmx commented Jun 25, 2018

Please squash merge (as mentioned on the other PRs :)

@richardschneider
Copy link
Contributor Author

I'll look into the libraries and report back. I'm makaretu on IRC, what is your nickname,

@vmx
Copy link
Member

vmx commented Jun 25, 2018

I'm vmx on IRC.

@richardschneider richardschneider merged commit 1aed60e into master Jun 25, 2018
@richardschneider richardschneider deleted the cid-options branch June 25, 2018 08:10
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