1 | var util = require('multiblob/util')
|
2 | var isBlob = require('ssb-ref').isBlob
|
3 | var MultiBlob = require('multiblob')
|
4 |
|
5 | function desigil (hash) {
|
6 | return isBlob(hash) ? hash.substring(1) : hash
|
7 | }
|
8 |
|
9 | function resigil (hash) {
|
10 | return isBlob(hash) ? hash : '&' + hash
|
11 | }
|
12 |
|
13 | module.exports = function (dir) {
|
14 | return MultiBlob({
|
15 | dir: dir,
|
16 | alg: 'sha256',
|
17 | encode: function (buf, alg) {
|
18 | return resigil(util.encode(buf, alg))
|
19 | },
|
20 | decode: function (str) {
|
21 | return util.decode(desigil(str))
|
22 | },
|
23 | isHash: isBlob
|
24 | })
|
25 | }
|