git ssb

0+

wanderer🌟 / js-dfinity-radix-tree



Commit 3d628f57a11eceed9c7d6369490decbdade51afd

remove encoding crap

wanderer committed on 12/2/2017, 4:46:13 AM
Parent: b23a2f3c73ef7954a95ffa74177c3e67ab3df95c

Files changed

index.jschanged
package-lock.jsonchanged
package.jsonchanged
tests/index.jschanged
treeNode.jschanged
index.jsView
@@ -1,6 +1,5 @@
11 const Graph = require('ipld-graph-builder')
2-const cbor = require('borc')
32 const Uint1Array = require('uint1array')
43 const TextEncoder = require('text-encoding').TextEncoder
54 const DataStore = require('./datastore.js')
65 const treeNode = require('./treeNode.js')
@@ -45,14 +44,9 @@
4544 */
4645 async get (key, decode) {
4746 key = this.formatKey(key)
4847 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)
5549 }
5650
5751 async _get (key) {
5852 let index = 0
package-lock.jsonView
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.jsonView
@@ -26,9 +26,8 @@
2626 "standard": "^10.0.0",
2727 "tape": "^4.6.3"
2828 },
2929 "dependencies": {
30- "borc": "^2.0.2",
3130 "buffer-pipe": "0.0.0",
3231 "ipld-graph-builder": "^1.3.5",
3332 "leb128": "0.0.4",
3433 "node-webcrypto-shim": "0.0.0",
tests/index.jsView
@@ -148,24 +148,8 @@
148148 t.equals(value.value.toString(), saved.toString())
149149 t.end()
150150 })
151151
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-
168152 tape('errors', async t => {
169153 const tree = new RadixTree({
170154 db: db,
171155 root: {
treeNode.jsView
@@ -1,7 +1,6 @@
1-const borc = require('borc')
21 const leb128 = require('leb128').unsigned
3-const LebStream = require('buffer-pipe')
2 +const BufferPipe = require('buffer-pipe')
43 const Uint1Array = require('uint1array')
54 const HASH_LEN = 20
65
76 function toTypedArray (array) {
@@ -90,11 +89,8 @@
9089 }
9190
9291 let val = node[VALUE]
9392 if (val !== undefined) {
94- if (!val.buffer) {
95- val = borc.encode(val)
96- }
9793 encoded.push(val)
9894 prefix += MASK.VALUE
9995 }
10096
@@ -109,29 +105,29 @@
109105
110106 exports.decode = function (val) {
111107 const node = [null, null, null]
112108 const prefix = val[0]
113- const lebStream = new LebStream(val.slice(1))
109 + const pipe = new BufferPipe(val.slice(1))
114110
115111 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))
118114 node[EXTENSION] = [len, ext]
119115 }
120116
121117 if (prefix & MASK.LBRANCH) {
122118 node[LBRANCH] = {
123- '/': lebStream.read(HASH_LEN)
119 + '/': pipe.read(HASH_LEN)
124120 }
125121 }
126122
127123 if (prefix & MASK.RBRANCH) {
128124 node[RBRANCH] = {
129- '/': lebStream.read(HASH_LEN)
125 + '/': pipe.read(HASH_LEN)
130126 }
131127 }
132128
133129 if (prefix & MASK.VALUE) {
134- node[VALUE] = lebStream.buffer
130 + node[VALUE] = pipe.buffer
135131 }
136132 return node
137133 }

Built with git-ssb-web