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

Commit

Permalink
feat(files.add): update API to conform latest interface-ipfs-core upd…
Browse files Browse the repository at this point in the history
…ates
  • Loading branch information
daviddias committed Aug 12, 2016
1 parent 3dddca2 commit 28b0bb7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions src/cli/commands/files/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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', () => {
Expand Down
16 changes: 11 additions & 5 deletions src/core/ipfs/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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--
})
})
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 28b0bb7

Please sign in to comment.