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

Commit 08312b9

Browse files
committed
fix(core/components/dag): make options in put API optional
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]>
1 parent 402b865 commit 08312b9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/core/components/dag.js

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ const flattenDeep = require('lodash.flattendeep')
99
module.exports = function dag (self) {
1010
return {
1111
put: promisify((dagNode, options, callback) => {
12+
if (typeof options === 'function') {
13+
callback = options
14+
}
15+
16+
const optionDefaults = {
17+
format: 'dag-cbor',
18+
hashAlg: 'sha2-256'
19+
}
20+
21+
options = options.cid ? options : Object.assign({}, optionDefaults, options)
22+
1223
self._ipld.put(dagNode, options, callback)
1324
}),
1425

0 commit comments

Comments
 (0)