This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(dag): basics (get and put)
- Loading branch information
Showing
6 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters