This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.js
65 lines (52 loc) · 1.55 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict'
const mh = require('multihashes')
const assert = require('assert')
const withIs = require('class-is')
// Link represents an IPFS Merkle DAG Link between Nodes.
class DAGLink {
constructor (name, size, multihash) {
assert(multihash, 'A link requires a multihash to point to')
// assert(size, 'A link requires a size')
// note - links should include size, but this assert is disabled
// for now to maintain consistency with go-ipfs pinset
this._name = name || ''
this._size = size
if (typeof multihash === 'string') {
this._multihash = mh.fromB58String(multihash)
} else if (Buffer.isBuffer(multihash)) {
this._multihash = multihash
}
}
toString () {
const mhStr = mh.toB58String(this.multihash)
return `DAGLink <${mhStr} - name: "${this.name}", size: ${this.size}>`
}
toJSON () {
return {
name: this.name,
size: this.size,
multihash: mh.toB58String(this._multihash)
}
}
get name () {
return this._name
}
set name (name) {
throw new Error("Can't set property: 'name' is immutable")
}
get size () {
return this._size
}
set size (size) {
throw new Error("Can't set property: 'size' is immutable")
}
get multihash () {
return this._multihash
}
set multihash (multihash) {
throw new Error("Can't set property: 'multihash' is immutable")
}
}
exports = module.exports = withIs(DAGLink, { className: 'DAGLink', symbolName: '@ipld/js-ipld-dag-pb/daglink' })
exports.create = require('./create')
exports.util = require('./util')