Commit 3d628f57a11eceed9c7d6369490decbdade51afd
remove encoding crap
wanderer committed on 12/2/2017, 4:46:13 AMParent: b23a2f3c73ef7954a95ffa74177c3e67ab3df95c
Files changed
index.js | changed |
package-lock.json | changed |
package.json | changed |
tests/index.js | changed |
treeNode.js | changed |
index.js | ||
---|---|---|
@@ -1,6 +1,5 @@ | ||
1 | 1 … | const Graph = require('ipld-graph-builder') |
2 | -const cbor = require('borc') | |
3 | 2 … | const Uint1Array = require('uint1array') |
4 | 3 … | const TextEncoder = require('text-encoding').TextEncoder |
5 | 4 … | const DataStore = require('./datastore.js') |
6 | 5 … | const treeNode = require('./treeNode.js') |
@@ -45,14 +44,9 @@ | ||
45 | 44 … | */ |
46 | 45 … | async get (key, decode) { |
47 | 46 … | key = this.formatKey(key) |
48 | 47 … | await this.done() |
49 | - let {root, value} = await this._get(key) | |
50 | - if (decode && Buffer.isBuffer(value)) { | |
51 | - value = cbor.decode(value) | |
52 | - treeNode.setValue(root, value) | |
53 | - } | |
54 | - return {root, value} | |
48 … | + return this._get(key) | |
55 | 49 … | } |
56 | 50 … | |
57 | 51 … | async _get (key) { |
58 | 52 … | let index = 0 |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 298081 bytes New file size: 296643 bytes |
package.json | ||
---|---|---|
@@ -26,9 +26,8 @@ | ||
26 | 26 … | "standard": "^10.0.0", |
27 | 27 … | "tape": "^4.6.3" |
28 | 28 … | }, |
29 | 29 … | "dependencies": { |
30 | - "borc": "^2.0.2", | |
31 | 30 … | "buffer-pipe": "0.0.0", |
32 | 31 … | "ipld-graph-builder": "^1.3.5", |
33 | 32 … | "leb128": "0.0.4", |
34 | 33 … | "node-webcrypto-shim": "0.0.0", |
tests/index.js | ||
---|---|---|
@@ -148,24 +148,8 @@ | ||
148 | 148 … | t.equals(value.value.toString(), saved.toString()) |
149 | 149 … | t.end() |
150 | 150 … | }) |
151 | 151 … | |
152 | -tape('encoding / decoding', async t => { | |
153 | - // t.plan(3) | |
154 | - const tree = new RadixTree({ | |
155 | - db: db | |
156 | - }) | |
157 | - | |
158 | - await tree.set('test', { | |
159 | - 'something': 1 | |
160 | - }) | |
161 | - await tree.flush() | |
162 | - | |
163 | - let r = await tree.get('test', true) | |
164 | - t.equals(r.value.something, 1, 'should correctly decode value') | |
165 | - t.end() | |
166 | -}) | |
167 | - | |
168 | 152 … | tape('errors', async t => { |
169 | 153 … | const tree = new RadixTree({ |
170 | 154 … | db: db, |
171 | 155 … | root: { |
treeNode.js | |||
---|---|---|---|
@@ -1,7 +1,6 @@ | |||
1 | -const borc = require('borc') | ||
2 | 1 … | const leb128 = require('leb128').unsigned | |
3 | -const LebStream = require('buffer-pipe') | ||
2 … | +const BufferPipe = require('buffer-pipe') | ||
4 | 3 … | const Uint1Array = require('uint1array') | |
5 | 4 … | const HASH_LEN = 20 | |
6 | 5 … | ||
7 | 6 … | function toTypedArray (array) { | |
@@ -90,11 +89,8 @@ | |||
90 | 89 … | } | |
91 | 90 … | ||
92 | 91 … | let val = node[VALUE] | |
93 | 92 … | if (val !== undefined) { | |
94 | - if (!val.buffer) { | ||
95 | - val = borc.encode(val) | ||
96 | - } | ||
97 | 93 … | encoded.push(val) | |
98 | 94 … | prefix += MASK.VALUE | |
99 | 95 … | } | |
100 | 96 … | ||
@@ -109,29 +105,29 @@ | |||
109 | 105 … | ||
110 | 106 … | exports.decode = function (val) { | |
111 | 107 … | const node = [null, null, null] | |
112 | 108 … | const prefix = val[0] | |
113 | - const lebStream = new LebStream(val.slice(1)) | ||
109 … | + const pipe = new BufferPipe(val.slice(1)) | ||
114 | 110 … | ||
115 | 111 … | if (prefix & MASK.EXTENSION) { | |
116 | - const len = Number(leb128.read(lebStream)) | ||
117 | - const ext = lebStream.read(Math.ceil(len / 8)) | ||
112 … | + const len = Number(leb128.read(pipe)) | ||
113 … | + const ext = pipe.read(Math.ceil(len / 8)) | ||
118 | 114 … | node[EXTENSION] = [len, ext] | |
119 | 115 … | } | |
120 | 116 … | ||
121 | 117 … | if (prefix & MASK.LBRANCH) { | |
122 | 118 … | node[LBRANCH] = { | |
123 | - '/': lebStream.read(HASH_LEN) | ||
119 … | + '/': pipe.read(HASH_LEN) | ||
124 | 120 … | } | |
125 | 121 … | } | |
126 | 122 … | ||
127 | 123 … | if (prefix & MASK.RBRANCH) { | |
128 | 124 … | node[RBRANCH] = { | |
129 | - '/': lebStream.read(HASH_LEN) | ||
125 … | + '/': pipe.read(HASH_LEN) | ||
130 | 126 … | } | |
131 | 127 … | } | |
132 | 128 … | ||
133 | 129 … | if (prefix & MASK.VALUE) { | |
134 | - node[VALUE] = lebStream.buffer | ||
130 … | + node[VALUE] = pipe.buffer | ||
135 | 131 … | } | |
136 | 132 … | return node | |
137 | 133 … | } |
Built with git-ssb-web