Skip to content

Commit

Permalink
fix(core/components/dag): make options in put API optional
Browse files Browse the repository at this point in the history
The [dag.put](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DAG.md#dagput) interface
takes an options object which is required, but should be optional with
decent defaults.

See dedicated test here: ipfs-inactive/interface-js-ipfs-core#316

This commit implements this behaviour.

**Before**:

```js
ipfs.dag.put(obj, options, (err, cid) => {...});
```

^ Prior to this commit, without passing `options`, this call resulted in an error.

**After**:

```js
ipfs.dag.put(obj, (err, cid) => {...});
```

^ This is now perfectly fine.

Fixes ipfs#1395

License: MIT
Signed-off-by: Pascal Precht <[email protected]>
  • Loading branch information
0x-r4bbit committed Jul 2, 2018
1 parent 402b865 commit 08312b9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/components/dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ const flattenDeep = require('lodash.flattendeep')
module.exports = function dag (self) {
return {
put: promisify((dagNode, options, callback) => {
if (typeof options === 'function') {
callback = options
}

const optionDefaults = {
format: 'dag-cbor',
hashAlg: 'sha2-256'
}

options = options.cid ? options : Object.assign({}, optionDefaults, options)

self._ipld.put(dagNode, options, callback)
}),

Expand Down

0 comments on commit 08312b9

Please sign in to comment.