From 74375770bee5172e2139cf16365e8e015ff2b2e8 Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Thu, 29 Sep 2016 11:00:02 +0200 Subject: [PATCH] more async fixes --- package.json | 3 +++ src/add-to-dagnode-transform.js | 23 ++++++++++++----------- src/api/object.js | 28 ++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 6126c86e5..654421b48 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/add-to-dagnode-transform.js b/src/add-to-dagnode-transform.js index 32de7f698..e87a2d960 100644 --- a/src/add-to-dagnode-transform.js +++ b/src/add-to-dagnode-transform.js @@ -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) } diff --git a/src/api/object.js b/src/api/object.js index 787b36276..eab875306 100644 --- a/src/api/object.js +++ b/src/api/object.js @@ -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) => { @@ -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: {