From 28b0bb7f63d899a18a2e5a46ae10d353766c2143 Mon Sep 17 00:00:00 2001 From: David Dias Date: Fri, 12 Aug 2016 17:36:46 +0100 Subject: [PATCH] feat(files.add): update API to conform latest interface-ipfs-core updates --- package.json | 2 +- src/cli/commands/files/add.js | 7 ++++--- src/core/ipfs/files.js | 16 +++++++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index fa2f578af8..c110eb5020 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "form-data": "^1.0.0-rc4", "gulp": "^3.9.1", "idb-plus-blob-store": "^1.1.2", - "interface-ipfs-core": "^0.7.2", + "interface-ipfs-core": "^0.8.0", "left-pad": "^1.1.1", "lodash": "^4.14.1", "ncp": "^2.0.0", diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index 0d26af066d..f82688b7bb 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -4,7 +4,6 @@ const utils = require('../../utils') const debug = require('debug') const log = debug('cli:version') log.error = debug('cli:version:error') -const bs58 = require('bs58') const fs = require('fs') const path = require('path') const glob = require('glob') @@ -68,8 +67,10 @@ module.exports = { const added = [] i.on('data', (file) => { - const hash = bs58.encode(file.node.multihash()).toString() - added.push({hash, path: file.path}) + added.push({ + hash: file.hash, + path: file.path + }) }) i.on('end', () => { diff --git a/src/core/ipfs/files.js b/src/core/ipfs/files.js index 1578ec9758..03e8689fcc 100644 --- a/src/core/ipfs/files.js +++ b/src/core/ipfs/files.js @@ -30,11 +30,16 @@ module.exports = function files (self) { i.on('data', (file) => { counter++ + const bs58mh = multihashes.toB58String(file.multihash) self.object.get(file.multihash, (err, node) => { if (err) { return ds.emit('error', err) } - ds.push({path: file.path, node: node}) + ds.push({ + path: file.path, + hash: bs58mh, + size: node.size() + }) counter-- }) }) @@ -79,12 +84,13 @@ module.exports = function files (self) { // Transform file info tuples to DAGNodes i.pipe(through.obj((info, enc, next) => { - const mh = multihashes.toB58String(info.multihash) - self._dagS.get(mh, (err, node) => { + const bs58mh = multihashes.toB58String(info.multihash) + self._dagS.get(bs58mh, (err, node) => { if (err) return callback(err) var obj = { - path: info.path || mh, - node: node + path: info.path || bs58mh, + hash: bs58mh, + size: node.size() } res.push(obj) next()