This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree 4 files changed +62
-0
lines changed
4 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
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
+ rm : promisify ( ( cid , callback ) => {
31
+ // TODO once pinning is complete, this remove operation has to first
32
+ // verify that some pinning chain is not broken with the operation
33
+ self . _ipldResolver . remove ( cid , callback )
34
+ } ) ,
35
+ resolve : promisify ( ( cid , path , callback ) => {
36
+ self . _ipldResolver . resolve ( cid , path , callback )
37
+ } )
38
+ }
39
+ }
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ const bootstrap = require('./components/bootstrap')
18
18
const config = require ( './components/config' )
19
19
const block = require ( './components/block' )
20
20
const object = require ( './components/object' )
21
+ const dag = require ( './components/dag' )
21
22
const libp2p = require ( './components/libp2p' )
22
23
const swarm = require ( './components/swarm' )
23
24
const ping = require ( './components/ping' )
@@ -64,6 +65,7 @@ function IPFS (repoInstance) {
64
65
this . config = config ( this )
65
66
this . block = block ( this )
66
67
this . object = object ( this )
68
+ this . dag = dag ( this )
67
69
this . libp2p = libp2p ( this )
68
70
this . swarm = swarm ( this )
69
71
this . files = files ( this )
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ describe('interface-ipfs-core tests', () => {
10
10
require ( './files' )
11
11
require ( './generic' )
12
12
require ( './object' )
13
+ require ( './dag' )
13
14
if ( isNode ) {
14
15
require ( './swarm' )
15
16
require ( './pubsub' )
You can’t perform that action at this time.
0 commit comments