Commit 1d5b8ce3a8cd7e95f4f5918187cbd383ed870576
remove custom encoding
wanderer committed on 3/1/2018, 2:09:57 AMParent: e6e068b9aabc855accb38b1e1c5289d738cb142c
Files changed
package-lock.json | changed |
package.json | changed |
treeNode.js | changed |
package-lock.json | ||
---|---|---|
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.json | ||
---|---|---|
@@ -19,17 +19,17 @@ | ||
19 | 19 … | "dfinity" |
20 | 20 … | ], |
21 | 21 … | "devDependencies": { |
22 | 22 … | "coveralls": "^3.0.0", |
23 | - "documentation": "^5.3.5", | |
23 … | + "documentation": "^5.4.0", | |
24 | 24 … | "level-browserify": "^1.1.1", |
25 | 25 … | "nyc": "^11.3.0", |
26 | 26 … | "standard": "^11.0.0", |
27 | 27 … | "tape": "^4.6.3" |
28 | 28 … | }, |
29 | 29 … | "dependencies": { |
30 | 30 … | "borc": "^2.0.2", |
31 | - "ipld-graph-builder": "^1.3.5", | |
31 … | + "ipld-graph-builder": "^1.3.7", | |
32 | 32 … | "node-webcrypto-shim": "0.0.0", |
33 | 33 … | "text-encoding": "^0.6.4", |
34 | 34 … | "uint1array": "^1.0.5" |
35 | 35 … | }, |
treeNode.js | ||
---|---|---|
@@ -1,8 +1,5 @@ | ||
1 | -const leb128 = require('leb128').unsigned | |
2 | -const BufferPipe = require('buffer-pipe') | |
3 | 1 … | const Uint1Array = require('uint1array') |
4 | -const HASH_LEN = 20 | |
5 | 2 … | |
6 | 3 … | function toTypedArray (array) { |
7 | 4 … | return new Uint1Array(new Uint8Array(array).buffer) |
8 | 5 … | } |
@@ -64,66 +61,4 @@ | ||
64 | 61 … | LBRANCH: 4, |
65 | 62 … | RBRANCH: 2, |
66 | 63 … | VALUE: 1 |
67 | 64 … | } |
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