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

Commit

Permalink
feat(dag): basics (get, put) (#746)
Browse files Browse the repository at this point in the history
* feat(dag): basics (get and put)
  • Loading branch information
daviddias authored Feb 1, 2017
1 parent 69fa802 commit e5ec0cf
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"form-data": "^2.1.2",
"fs-pull-blob-store": "^0.4.1",
"gulp": "^3.9.1",
"interface-ipfs-core": "^0.23.5",
"interface-ipfs-core": "^0.23.8",
"ipfsd-ctl": "^0.18.1",
"left-pad": "^1.1.3",
"lodash": "^4.17.4",
Expand Down Expand Up @@ -171,4 +171,4 @@
"nginnever <ginneversource@gmail.com>",
"npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>"
]
}
}
34 changes: 34 additions & 0 deletions src/core/components/dag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'

const promisify = require('promisify-es6')

const dagPB = require('ipld-dag-pb')
const dagCBOR = require('ipld-dag-cbor')

module.exports = function dag (self) {
return {
put: promisify((dagNode, multicodec, hashAlg, callback) => {
switch (multicodec) {
case 'dag-pb': dagPB.util.cid(dagNode, gotCid); break
case 'dag-cbor': dagCBOR.util.cid(dagNode, gotCid); break
default: callback(new Error('IPLD Format not supported'))
}

function gotCid (err, cid) {
if (err) {
return callback(err)
}
self._ipldResolver.put({
node: dagNode,
cid: cid
}, callback)
}
}),
get: promisify((cid, callback) => {
self._ipldResolver.get(cid, callback)
}),
resolve: promisify((cid, path, callback) => {
self._ipldResolver.resolve(cid, path, callback)
})
}
}
1 change: 1 addition & 0 deletions src/core/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports.bootstrap = require('./bootstrap')
exports.config = require('./config')
exports.block = require('./block')
exports.object = require('./object')
exports.dag = require('./dag')
exports.libp2p = require('./libp2p')
exports.swarm = require('./swarm')
exports.ping = require('./ping')
Expand Down
1 change: 1 addition & 0 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class IPFS {
this.config = components.config(this)
this.block = components.block(this)
this.object = components.object(this)
this.dag = components.dag(this)
this.libp2p = components.libp2p(this)
this.swarm = components.swarm(this)
this.files = components.files(this)
Expand Down
20 changes: 20 additions & 0 deletions test/core/interface/dag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-env mocha */

'use strict'

const test = require('interface-ipfs-core')
const IPFSFactory = require('../../utils/factory-core')

let factory

const common = {
setup: function (cb) {
factory = new IPFSFactory()
cb(null, factory)
},
teardown: function (cb) {
factory.dismantle(cb)
}
}

test.dag(common)
1 change: 1 addition & 0 deletions test/core/interface/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('interface-ipfs-core tests', () => {
require('./files')
require('./generic')
require('./object')
require('./dag')
if (isNode) {
require('./swarm')
require('./pubsub')
Expand Down

0 comments on commit e5ec0cf

Please sign in to comment.