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

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 #1395

License: MIT
Signed-off-by: Pascal Precht <[email protected]>
  • Loading branch information
0x-r4bbit committed Jun 30, 2018
1 parent 402b865 commit 03f6073
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-pb',
hashAlg: 'sha2-256'
}

options = Object.assign({}, optionDefaults, options)

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

Expand Down

0 comments on commit 03f6073

Please sign in to comment.