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, rm)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Jan 31, 2017
1 parent 02efd7c commit a41ee1d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/core/components/dag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'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)
}),
rm: promisify((cid, callback) => {
// TODO once pinning is complete, this remove operation has to first
// verify that some pinning chain is not broken with the operation
self._ipldResolver.remove(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 a41ee1d

Please sign in to comment.