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 and put)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Feb 1, 2017
1 parent 02efd7c commit 49cbd2d
Show file tree
Hide file tree
Showing 5 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)
})
}
}
2 changes: 2 additions & 0 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const bootstrap = require('./components/bootstrap')
const config = require('./components/config')
const block = require('./components/block')
const object = require('./components/object')
const dag = require('./components/dag')
const libp2p = require('./components/libp2p')
const swarm = require('./components/swarm')
const ping = require('./components/ping')
Expand Down Expand Up @@ -64,6 +65,7 @@ function IPFS (repoInstance) {
this.config = config(this)
this.block = block(this)
this.object = object(this)
this.dag = dag(this)
this.libp2p = libp2p(this)
this.swarm = swarm(this)
this.files = 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 49cbd2d

Please sign in to comment.