Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 28b0bb7

Browse files
committed
feat(files.add): update API to conform latest interface-ipfs-core updates
1 parent 3dddca2 commit 28b0bb7

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"form-data": "^1.0.0-rc4",
4848
"gulp": "^3.9.1",
4949
"idb-plus-blob-store": "^1.1.2",
50-
"interface-ipfs-core": "^0.7.2",
50+
"interface-ipfs-core": "^0.8.0",
5151
"left-pad": "^1.1.1",
5252
"lodash": "^4.14.1",
5353
"ncp": "^2.0.0",

src/cli/commands/files/add.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const utils = require('../../utils')
44
const debug = require('debug')
55
const log = debug('cli:version')
66
log.error = debug('cli:version:error')
7-
const bs58 = require('bs58')
87
const fs = require('fs')
98
const path = require('path')
109
const glob = require('glob')
@@ -68,8 +67,10 @@ module.exports = {
6867
const added = []
6968

7069
i.on('data', (file) => {
71-
const hash = bs58.encode(file.node.multihash()).toString()
72-
added.push({hash, path: file.path})
70+
added.push({
71+
hash: file.hash,
72+
path: file.path
73+
})
7374
})
7475

7576
i.on('end', () => {

src/core/ipfs/files.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ module.exports = function files (self) {
3030

3131
i.on('data', (file) => {
3232
counter++
33+
const bs58mh = multihashes.toB58String(file.multihash)
3334
self.object.get(file.multihash, (err, node) => {
3435
if (err) {
3536
return ds.emit('error', err)
3637
}
37-
ds.push({path: file.path, node: node})
38+
ds.push({
39+
path: file.path,
40+
hash: bs58mh,
41+
size: node.size()
42+
})
3843
counter--
3944
})
4045
})
@@ -79,12 +84,13 @@ module.exports = function files (self) {
7984

8085
// Transform file info tuples to DAGNodes
8186
i.pipe(through.obj((info, enc, next) => {
82-
const mh = multihashes.toB58String(info.multihash)
83-
self._dagS.get(mh, (err, node) => {
87+
const bs58mh = multihashes.toB58String(info.multihash)
88+
self._dagS.get(bs58mh, (err, node) => {
8489
if (err) return callback(err)
8590
var obj = {
86-
path: info.path || mh,
87-
node: node
91+
path: info.path || bs58mh,
92+
hash: bs58mh,
93+
size: node.size()
8894
}
8995
res.push(obj)
9096
next()

0 commit comments

Comments
 (0)