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

Commit e5ec0cf

Browse files
authored
feat(dag): basics (get, put) (#746)
* feat(dag): basics (get and put)
1 parent 69fa802 commit e5ec0cf

File tree

6 files changed

+59
-2
lines changed

6 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.8",
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/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exports.bootstrap = require('./bootstrap')
1212
exports.config = require('./config')
1313
exports.block = require('./block')
1414
exports.object = require('./object')
15+
exports.dag = require('./dag')
1516
exports.libp2p = require('./libp2p')
1617
exports.swarm = require('./swarm')
1718
exports.ping = require('./ping')

src/core/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class IPFS {
5252
this.config = components.config(this)
5353
this.block = components.block(this)
5454
this.object = components.object(this)
55+
this.dag = components.dag(this)
5556
this.libp2p = components.libp2p(this)
5657
this.swarm = components.swarm(this)
5758
this.files = components.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)