Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit bcb89de

Browse files
committed
wip: migrate object api to async dag-pb
1 parent ad96d22 commit bcb89de

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"flatmap": "0.0.3",
2626
"glob": "^7.1.1",
2727
"ipfs-block": "^0.4.0",
28-
"ipld-dag-pb": "^0.1.2",
28+
"ipld-dag-pb": "^0.1.3",
2929
"is-ipfs": "^0.2.0",
3030
"isstream": "^0.1.2",
3131
"multiaddr": "^2.0.2",

src/api/object.js

+33-11
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,37 @@ module.exports = (send) => {
9494
obj = JSON.parse(obj.toString())
9595
}
9696
}
97+
9798
let node
99+
98100
if (obj.multihash) {
99101
node = obj
100102
} else if (options.enc === 'protobuf') {
101-
node = new DAGNode()
102-
node.unMarshal(obj)
103+
dagPB.util.deserialize(obj, (err, _node) => {
104+
if (err) {
105+
return callback(err)
106+
}
107+
node = _node
108+
next()
109+
})
110+
return
103111
} else {
104112
node = new DAGNode(obj.Data, obj.Links)
105113
}
106-
107-
if (node.toJSON().Hash !== result.Hash) {
108-
return callback(new Error('Stored object was different from constructed object'))
114+
next()
115+
116+
function next () {
117+
node.toJSON((err, nodeJSON) => {
118+
if (err) {
119+
return callback(err)
120+
}
121+
if (nodeJSON.Hash !== result.Hash) {
122+
return callback(new Error('Stored object was different from constructed object'))
123+
}
124+
125+
callback(null, node)
126+
})
109127
}
110-
111-
callback(null, node)
112128
})
113129
}),
114130
data: promisify((multihash, options, callback) => {
@@ -201,13 +217,19 @@ module.exports = (send) => {
201217
if (err) {
202218
return callback(err)
203219
}
220+
204221
const node = new DAGNode()
222+
node.toJSON((err, nodeJSON) => {
223+
if (err) {
224+
return callback(err)
225+
}
205226

206-
if (node.toJSON().Hash !== result.Hash) {
207-
return callback(new Error('Stored object was different from constructed object'))
208-
}
227+
if (nodeJSON.Hash !== result.Hash) {
228+
return callback(new Error('Stored object was different from constructed object'))
229+
}
209230

210-
callback(null, node)
231+
callback(null, node)
232+
})
211233
})
212234
}),
213235
patch: {

0 commit comments

Comments
 (0)