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

Commit d70da11

Browse files
committed
feat(dag): basics (get and put)
1 parent 02efd7c commit d70da11

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"form-data": "^2.1.2",
7373
"fs-pull-blob-store": "^0.4.1",
7474
"gulp": "^3.9.1",
75-
"interface-ipfs-core": "^0.23.5",
75+
"interface-ipfs-core": "^0.23.7",
7676
"ipfsd-ctl": "^0.18.1",
7777
"left-pad": "^1.1.3",
7878
"lodash": "^4.17.4",
@@ -171,4 +171,4 @@
171171
"nginnever <[email protected]>",
172172
"npmcdn-to-unpkg-bot <[email protected]>"
173173
]
174-
}
174+
}

src/core/components/dag.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict'
2+
3+
const promisify = require('promisify-es6')
4+
5+
const dagPB = require('ipld-dag-pb')
6+
const dagCBOR = require('ipld-dag-cbor')
7+
8+
module.exports = function dag (self) {
9+
return {
10+
put: promisify((dagNode, multicodec, hashAlg, callback) => {
11+
switch (multicodec) {
12+
case 'dag-pb': dagPB.util.cid(dagNode, gotCid); break
13+
case 'dag-cbor': dagCBOR.util.cid(dagNode, gotCid); break
14+
default: callback(new Error('IPLD Format not supported'))
15+
}
16+
17+
function gotCid (err, cid) {
18+
if (err) {
19+
return callback(err)
20+
}
21+
self._ipldResolver.put({
22+
node: dagNode,
23+
cid: cid
24+
}, callback)
25+
}
26+
}),
27+
get: promisify((cid, callback) => {
28+
self._ipldResolver.get(cid, callback)
29+
}),
30+
resolve: promisify((cid, path, callback) => {
31+
self._ipldResolver.resolve(cid, path, callback)
32+
})
33+
}
34+
}

src/core/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const bootstrap = require('./components/bootstrap')
1818
const config = require('./components/config')
1919
const block = require('./components/block')
2020
const object = require('./components/object')
21+
const dag = require('./components/dag')
2122
const libp2p = require('./components/libp2p')
2223
const swarm = require('./components/swarm')
2324
const ping = require('./components/ping')
@@ -64,6 +65,7 @@ function IPFS (repoInstance) {
6465
this.config = config(this)
6566
this.block = block(this)
6667
this.object = object(this)
68+
this.dag = dag(this)
6769
this.libp2p = libp2p(this)
6870
this.swarm = swarm(this)
6971
this.files = files(this)

test/core/interface/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)

test/core/interface/interface.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('interface-ipfs-core tests', () => {
1010
require('./files')
1111
require('./generic')
1212
require('./object')
13+
require('./dag')
1314
if (isNode) {
1415
require('./swarm')
1516
require('./pubsub')

0 commit comments

Comments
 (0)