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

Commit

Permalink
more async fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Sep 29, 2016
1 parent 44f91eb commit 01ce368
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"browser": {
"glob": false
},
"scripts": {
"test": "PHANTOM=off node --max_old_space_size=4096 node_modules/.bin/gulp test:node",
"test:node": "gulp test:node",
Expand Down
23 changes: 12 additions & 11 deletions src/add-to-dagnode-transform.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
'use strict'

const map = require('async/map')
const waterfall = require('async/waterfall')

const getDagNode = require('./get-dagnode')

// transform { Hash: '...' } objects into { path: 'string', node: DAGNode }
module.exports = function (err, res, send, done) {
module.exports = (err, res, send, done) => {
if (err) {
return done(err)
}

map(res, function map (entry, next) {
getDagNode(send, entry.Hash, function (err, node) {
map(res, (entry, next) => waterfall([
(cb) => getDagNode(send, entry.Hash, cb),
(node, cb) => node.size((err, size) => {
if (err) {
return next(err)
return cb(err)
}
var obj = {

next(null, {
path: entry.Name,
hash: entry.Hash,
size: node.size()
}
next(null, obj)
size: size
})
})
}, function (err, res) {
done(err, res)
})
], next), done)
}
28 changes: 20 additions & 8 deletions src/api/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,17 @@ module.exports = (send) => {
node = new DAGNode(obj.Data, obj.Links)
}

if (node.toJSON().Hash !== result.Hash) {
return callback(new Error('Stored object was different from constructed object'))
}
node.toJSON((err, json) => {
if (err) {
return callback(err)
}

callback(null, node)
if (json.Hash !== result.Hash) {
return callback(new Error('Stored object was different from constructed object'))
}

callback(null, node)
})
})
}),
data: promisify((multihash, options, callback) => {
Expand Down Expand Up @@ -202,11 +208,17 @@ module.exports = (send) => {
}
const node = new DAGNode()

if (node.toJSON().Hash !== result.Hash) {
return callback(new Error('Stored object was different from constructed object'))
}
node.toJSON((err, json) => {
if (err) {
return callback(err)
}

callback(null, node)
if (json.Hash !== result.Hash) {
return callback(new Error('Stored object was different from constructed object'))
}

callback(null, node)
})
})
}),
patch: {
Expand Down

0 comments on commit 01ce368

Please sign in to comment.