git ssb

0+

wanderer🌟 / js-dfinity-radix-tree



Commit 1d5b8ce3a8cd7e95f4f5918187cbd383ed870576

remove custom encoding

wanderer committed on 3/1/2018, 2:09:57 AM
Parent: e6e068b9aabc855accb38b1e1c5289d738cb142c

Files changed

package-lock.jsonchanged
package.jsonchanged
treeNode.jschanged
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 322409 bytes
New file size: 327883 bytes
package.jsonView
@@ -19,17 +19,17 @@
1919 "dfinity"
2020 ],
2121 "devDependencies": {
2222 "coveralls": "^3.0.0",
23- "documentation": "^5.3.5",
23 + "documentation": "^5.4.0",
2424 "level-browserify": "^1.1.1",
2525 "nyc": "^11.3.0",
2626 "standard": "^11.0.0",
2727 "tape": "^4.6.3"
2828 },
2929 "dependencies": {
3030 "borc": "^2.0.2",
31- "ipld-graph-builder": "^1.3.5",
31 + "ipld-graph-builder": "^1.3.7",
3232 "node-webcrypto-shim": "0.0.0",
3333 "text-encoding": "^0.6.4",
3434 "uint1array": "^1.0.5"
3535 },
treeNode.jsView
@@ -1,8 +1,5 @@
1-const leb128 = require('leb128').unsigned
2-const BufferPipe = require('buffer-pipe')
31 const Uint1Array = require('uint1array')
4-const HASH_LEN = 20
52
63 function toTypedArray (array) {
74 return new Uint1Array(new Uint8Array(array).buffer)
85 }
@@ -64,66 +61,4 @@
6461 LBRANCH: 4,
6562 RBRANCH: 2,
6663 VALUE: 1
6764 }
68-
69-exports.encode = function (node, prefix = 0, encodeLen = false) {
70- let encoded = []
71- const ext = node[EXTENSION]
72- if (ext) {
73- const len = leb128.encode(ext[0])
74- encoded.push(len)
75- encoded.push(ext[1])
76- prefix += MASK.EXTENSION
77- }
78-
79- const lb = node[LBRANCH]
80- if (lb) {
81- encoded.push(lb['/'])
82- prefix += MASK.LBRANCH
83- }
84-
85- const rb = node[RBRANCH]
86- if (rb) {
87- encoded.push(rb['/'])
88- prefix += MASK.RBRANCH
89- }
90-
91- let val = node[VALUE]
92- if (val !== undefined) {
93- encoded.push(val)
94- prefix += MASK.VALUE
95- }
96-
97- encoded.unshift(Buffer.from([prefix]))
98- encoded = Buffer.concat(encoded)
99- return encoded
100-}
101-
102-exports.decode = function (val) {
103- const node = [null, null, null]
104- const prefix = val[0]
105- const pipe = new BufferPipe(val.slice(1))
106-
107- if (prefix & MASK.EXTENSION) {
108- const len = Number(leb128.read(pipe))
109- const ext = pipe.read(Math.ceil(len / 8))
110- node[EXTENSION] = [len, ext]
111- }
112-
113- if (prefix & MASK.LBRANCH) {
114- node[LBRANCH] = {
115- '/': pipe.read(HASH_LEN)
116- }
117- }
118-
119- if (prefix & MASK.RBRANCH) {
120- node[RBRANCH] = {
121- '/': pipe.read(HASH_LEN)
122- }
123- }
124-
125- if (prefix & MASK.VALUE) {
126- node[VALUE] = pipe.buffer
127- }
128- return node
129-}

Built with git-ssb-web