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

Commit 16ad10c

Browse files
committed
feat: dag.get, dag.rm and dag.resolve
1 parent b5b166b commit 16ad10c

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

src/core/components/dag.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const dagPB = require('ipld-dag-pb')
5-
const CID = require('cids')
4+
// const dagPB = require('ipld-dag-pb')
5+
// const dagCBOR = require('ipld-dag-cbor')
6+
7+
// const CID = require('cids')
68
// const mh = require('multihashes')
79

8-
module.exports = function object (self) {
10+
module.exports = function dag (self) {
911
return {
1012
put: promisify((dagNode, multicodec, hashAlg, callback) => {
1113
// TODO
@@ -15,17 +17,28 @@ module.exports = function object (self) {
1517
// put in IPLD Resolver
1618

1719
/*
18-
self._ipldResolver.put({
19-
node: node,
20-
cid: new CID(node.multihash)
21-
}
20+
self._ipldResolver.put({
21+
node: node,
22+
cid: new CID(node.multihash)
23+
}
2224
*/
25+
switch (multicodec) {
26+
case 'dag-pb': {} break
27+
case 'dag-cbor': {} break
28+
default:
29+
callback(new Error('IPLD Format not supported'))
30+
}
2331
}),
2432
get: promisify((cid, callback) => {
2533
self.ipldResolver.get(cid, callback)
2634
}),
35+
rm: promisify((cid, callback) => {
36+
// TODO once pinning is complete, this remove operation has to first
37+
// verify that some pinning chain is not broken with the operation
38+
self.ipldResolver.remove(cid, callback)
39+
}),
2740
resolve: promisify((cid, path, callback) => {
28-
// TODO
41+
self.ipldResolver.resolve(cid, path, callback)
2942
})
3043
}
3144
}

test/core/both/test-dag.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-env mocha */
2+
3+
'use strict'
4+
5+
const test = require('interface-ipfs-core')
6+
const IPFSFactory = require('../../utils/factory-core')
7+
8+
let factory
9+
10+
const common = {
11+
setup: function (cb) {
12+
factory = new IPFSFactory()
13+
cb(null, factory)
14+
},
15+
teardown: function (cb) {
16+
factory.dismantle(cb)
17+
}
18+
}
19+
20+
test.dag(common)

0 commit comments

Comments
 (0)