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

Commit 01ce368

Browse files
more async fixes
1 parent 44f91eb commit 01ce368

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec",
55
"main": "lib/index.js",
66
"jsnext:main": "src/index.js",
7+
"browser": {
8+
"glob": false
9+
},
710
"scripts": {
811
"test": "PHANTOM=off node --max_old_space_size=4096 node_modules/.bin/gulp test:node",
912
"test:node": "gulp test:node",

src/add-to-dagnode-transform.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
'use strict'
22

33
const map = require('async/map')
4+
const waterfall = require('async/waterfall')
5+
46
const getDagNode = require('./get-dagnode')
57

68
// transform { Hash: '...' } objects into { path: 'string', node: DAGNode }
7-
module.exports = function (err, res, send, done) {
9+
module.exports = (err, res, send, done) => {
810
if (err) {
911
return done(err)
1012
}
1113

12-
map(res, function map (entry, next) {
13-
getDagNode(send, entry.Hash, function (err, node) {
14+
map(res, (entry, next) => waterfall([
15+
(cb) => getDagNode(send, entry.Hash, cb),
16+
(node, cb) => node.size((err, size) => {
1417
if (err) {
15-
return next(err)
18+
return cb(err)
1619
}
17-
var obj = {
20+
21+
next(null, {
1822
path: entry.Name,
1923
hash: entry.Hash,
20-
size: node.size()
21-
}
22-
next(null, obj)
24+
size: size
25+
})
2326
})
24-
}, function (err, res) {
25-
done(err, res)
26-
})
27+
], next), done)
2728
}

src/api/object.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,17 @@ module.exports = (send) => {
103103
node = new DAGNode(obj.Data, obj.Links)
104104
}
105105

106-
if (node.toJSON().Hash !== result.Hash) {
107-
return callback(new Error('Stored object was different from constructed object'))
108-
}
106+
node.toJSON((err, json) => {
107+
if (err) {
108+
return callback(err)
109+
}
109110

110-
callback(null, node)
111+
if (json.Hash !== result.Hash) {
112+
return callback(new Error('Stored object was different from constructed object'))
113+
}
114+
115+
callback(null, node)
116+
})
111117
})
112118
}),
113119
data: promisify((multihash, options, callback) => {
@@ -202,11 +208,17 @@ module.exports = (send) => {
202208
}
203209
const node = new DAGNode()
204210

205-
if (node.toJSON().Hash !== result.Hash) {
206-
return callback(new Error('Stored object was different from constructed object'))
207-
}
211+
node.toJSON((err, json) => {
212+
if (err) {
213+
return callback(err)
214+
}
208215

209-
callback(null, node)
216+
if (json.Hash !== result.Hash) {
217+
return callback(new Error('Stored object was different from constructed object'))
218+
}
219+
220+
callback(null, node)
221+
})
210222
})
211223
}),
212224
patch: {

0 commit comments

Comments
 (0)