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

feat/awesome dag-pb #625

Merged
merged 11 commits into from
Nov 26, 2016
3 changes: 2 additions & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ module.exports = {
included: false
}]
}
}
}

2 changes: 1 addition & 1 deletion examples/bundle-browserify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var IPFS = require('ipfs')
// Create the IPFS node instance
// for simplicity, we create a new repo everytime the node
// is created, because you can't init already existing repos
const repoPath = '' + Math.random()
const repoPath = String(Math.random())
const node = new IPFS(repoPath)
const concat = require('concat-stream')

Expand Down
2 changes: 1 addition & 1 deletion examples/bundle-webpack/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class App extends React.Component {

// for simplicity, we create a new repo everytime the node
// is created, because you can't init already existing repos
const repoPath = '' + Math.random()
const repoPath = String(Math.random())
node = new IPFS(repoPath)

node.init({ emptyRepo: true, bits: 2048 }, function (err) {
Expand Down
2 changes: 2 additions & 0 deletions examples/bundle-webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

var path = require('path')
var webpack = require('webpack')

Expand Down
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"detect-node": "^2.0.3",
"eslint-plugin-react": "^6.7.1",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, it was because of the added example? 💥

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

"execa": "^0.5.0",
"expose-loader": "^0.7.1",
"form-data": "^2.1.2",
"fs-pull-blob-store": "^0.4.1",
"gulp": "^3.9.1",
"interface-ipfs-core": "^0.18.4",
"interface-ipfs-core": "^0.22.0",
"left-pad": "^1.1.3",
"lodash": "^4.17.1",
"lodash": "^4.17.2",
"ncp": "^2.0.0",
"nexpect": "^0.5.0",
"pre-commit": "^1.1.3",
Expand All @@ -70,7 +71,7 @@
"transform-loader": "^0.2.3"
},
"dependencies": {
"async": "^2.1.2",
"async": "^2.1.4",
"bl": "^1.1.2",
"boom": "^4.2.0",
"debug": "^2.3.3",
Expand All @@ -79,17 +80,17 @@
"hapi": "^15.2.0",
"hapi-set-header": "^1.0.2",
"idb-pull-blob-store": "^0.5.1",
"ipfs-api": "^11.1.0",
"ipfs-api": "^12.0.0",
"ipfs-bitswap": "^0.8.1",
"ipfs-block": "^0.5.0",
"ipfs-block-service": "^0.7.0",
"ipfs-multipart": "^0.1.0",
"ipfs-repo": "^0.11.1",
"ipfs-unixfs": "^0.1.5",
"ipfs-unixfs-engine": "^0.13.0",
"ipld-resolver": "^0.2.0",
"ipfs-unixfs-engine": "^0.14.0",
"ipld-resolver": "^0.3.0",
"isstream": "^0.1.2",
"joi": "^9.2.0",
"joi": "^10.0.1",
"libp2p-ipfs": "^0.15.0",
"libp2p-ipfs-browser": "^0.16.0",
"lodash.flatmap": "^4.5.0",
Expand All @@ -99,12 +100,12 @@
"lodash.sortby": "^4.7.0",
"lodash.values": "^4.3.0",
"mafmt": "^2.1.2",
"multiaddr": "^2.0.3",
"multiaddr": "^2.1.1",
"multihashes": "^0.2.2",
"path-exists": "^3.0.0",
"peer-book": "^0.3.0",
"peer-id": "^0.8.0",
"peer-info": "^0.8.0",
"peer-info": "^0.8.1",
"promisify-es6": "^1.0.2",
"pull-file": "^1.0.0",
"pull-paramap": "^1.2.1",
Expand All @@ -114,7 +115,7 @@
"pull-stream-to-stream": "^1.3.3",
"pull-zip": "^2.0.1",
"read-pkg-up": "^2.0.0",
"readable-stream": "^1.1.14",
"readable-stream": "1.1.14",
"stream-to-pull-stream": "^1.7.2",
"tar-stream": "^1.5.2",
"temp": "^0.8.3",
Expand Down Expand Up @@ -147,4 +148,4 @@
"nginnever <ginneversource@gmail.com>",
"npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>"
]
}
}
24 changes: 19 additions & 5 deletions src/cli/commands/object/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,29 @@ module.exports = {
handler (argv) {
waterfall([
(cb) => utils.getIPFS(cb),
(ipfs, cb) => ipfs.object.get(argv.key, {enc: 'base58'}, cb),
(node, cb) => node.toJSON(cb)
], (err, nodeJson) => {
(ipfs, cb) => ipfs.object.get(argv.key, {enc: 'base58'}, cb)
], (err, node) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please refrain from these cosmetic changes, I will change it back in the next commit any way and it makes it harder to see the relevant changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point! :)

if (err) {
throw err
}
const nodeJSON = node.toJSON()

nodeJson.Data = nodeJson.Data ? nodeJson.Data.toString() : ''
console.log(JSON.stringify(nodeJson))
nodeJSON.data = nodeJSON.data ? nodeJSON.data.toString() : ''

const answer = {
Data: nodeJSON.data,
Hash: nodeJSON.multihash,
Size: nodeJSON.size,
Links: nodeJSON.links.map((l) => {
return {
Name: l.name,
Size: l.size,
Hash: l.multihash
}
})
}

console.log(JSON.stringify(answer))
})
}
}
7 changes: 6 additions & 1 deletion src/cli/commands/object/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ module.exports = {

links.forEach((link) => {
link = link.toJSON()
console.log(link.Hash, link.Size, link.Name)

console.log(
link.multihash,
link.size,
link.name
)
})
})
})
Expand Down
7 changes: 4 additions & 3 deletions src/cli/commands/object/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ module.exports = {
handler (argv) {
waterfall([
(cb) => utils.getIPFS(cb),
(ipfs, cb) => ipfs.object.new(cb),
(node, cb) => node.toJSON(cb)
(ipfs, cb) => ipfs.object.new(cb)
], (err, node) => {
if (err) {
throw err
}

console.log(node.Hash)
const nodeJSON = node.toJSON()

console.log(nodeJSON.multihash)
})
}
}
58 changes: 37 additions & 21 deletions src/cli/commands/object/patch/add-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const debug = require('debug')
const log = debug('cli:object')
const dagPB = require('ipld-dag-pb')
const DAGLink = dagPB.DAGLink
const waterfall = require('async/waterfall')
const parallel = require('async/parallel')
const series = require('async/series')
log.error = debug('cli:object:error')

module.exports = {
Expand All @@ -17,29 +16,46 @@ module.exports = {
builder: {},

handler (argv) {
waterfall([
(cb) => utils.getIPFS(cb),
(ipfs, cb) => waterfall([
(cb) => ipfs.object.get(argv.ref, {enc: 'base58'}, cb),
(linkedObj, cb) => parallel([
(cb) => linkedObj.size(cb),
(cb) => linkedObj.multihash(cb)
], cb)
], (err, stats) => {
if (err) {
return cb(err)
}

const link = new DAGLink(argv.name, stats[0], stats[1])
ipfs.object.patch.addLink(argv.root, link, {enc: 'base58'}, cb)
}),
(node, cb) => node.toJSON(cb)
], (err, node) => {
let ipfs
let nodeA
let nodeB

series([
(cb) => {
utils.getIPFS((err, _ipfs) => {
if (err) {
return cb(err)
}
ipfs = _ipfs
cb()
})
},
(cb) => {
ipfs.object.get(argv.ref, {enc: 'base58'}, (err, node) => {
if (err) {
return cb(err)
}
nodeA = node
cb()
})
},
(cb) => {
const link = new DAGLink(argv.name, nodeA.size, nodeA.multihash)

ipfs.object.patch.addLink(argv.root, link, {enc: 'base58'}, (err, node) => {
if (err) {
return cb(err)
}
nodeB = node
cb()
})
}
], (err) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a lot more complex and harder to read then before :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is also my attempt of trying to break each step by parts so that I can debug what is happening

if (err) {
throw err
}

console.log(node.Hash)
console.log(nodeB.toJSON().multihash)
})
}
}
6 changes: 3 additions & 3 deletions src/cli/commands/object/patch/append-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ log.error = debug('cli:object:error')
function appendData (key, data) {
waterfall([
(cb) => utils.getIPFS(cb),
(ipfs, cb) => ipfs.object.patch.appendData(key, data, {enc: 'base58'}, cb),
(node, cb) => node.toJSON(cb)
(ipfs, cb) => ipfs.object.patch.appendData(key, data, {enc: 'base58'}, cb)
], (err, node) => {
if (err) {
throw err
}
const nodeJSON = node.toJSON()

console.log(node.Hash)
console.log(nodeJSON.multihash)
})
}

Expand Down
13 changes: 9 additions & 4 deletions src/cli/commands/object/patch/rm-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@ module.exports = {
builder: {},

handler (argv) {
const dLink = new DAGLink(argv.link)
// TODO rmLink should support removing by name and/or multihash
// without having to know everything, which in fact it does, however,
// since it expectes a DAGLink type, we have to pass some fake size and
// hash.
const link = new DAGLink(argv.link, 1, 'Qm')

waterfall([
(cb) => utils.getIPFS(cb),
(ipfs, cb) => ipfs.object.patch.rmLink(argv.root, dLink, {enc: 'base58'}, cb),
(node, cb) => node.toJSON(cb)
(ipfs, cb) => ipfs.object.patch.rmLink(argv.root, link, {enc: 'base58'}, cb)
], (err, node) => {
if (err) {
throw err
}

console.log(node.Hash)
const nodeJSON = node.toJSON()

console.log(nodeJSON.multihash)
})
}
}
6 changes: 3 additions & 3 deletions src/cli/commands/object/patch/set-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ log.error = debug('cli:object:error')
function parseAndAddNode (key, data) {
waterfall([
(cb) => utils.getIPFS(cb),
(ipfs, cb) => ipfs.object.patch.setData(key, data, {enc: 'base58'}, cb),
(node, cb) => node.toJSON(cb)
(ipfs, cb) => ipfs.object.patch.setData(key, data, {enc: 'base58'}, cb)
], (err, node) => {
if (err) {
throw err
}
const nodeJSON = node.toJSON()

console.log(node.Hash)
console.log(nodeJSON.multihash)
})
}

Expand Down
11 changes: 7 additions & 4 deletions src/cli/commands/object/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ log.error = debug('cli:object:error')
function putNode (buf, enc) {
waterfall([
(cb) => utils.getIPFS(cb),
(ipfs, cb) => ipfs.object.put(buf, {enc: enc}, cb),
(node, cb) => node.toJSON(cb)
(ipfs, cb) => ipfs.object.put(buf, {enc: enc}, cb)
], (err, node) => {
if (err) {
throw err
}

console.log('added', node.Hash)
const nodeJSON = node.toJSON()

console.log('added', nodeJSON.multihash)
})
}

Expand All @@ -36,7 +37,9 @@ module.exports = {

handler (argv) {
if (argv.data) {
return putNode(fs.readFileSync(argv.data), argv.inputenc)
const buf = fs.readFileSync(argv.data)
putNode(buf, argv.inputenc)
return
}

process.stdin.pipe(bl((err, input) => {
Expand Down
6 changes: 3 additions & 3 deletions src/cli/commands/swarm/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ module.exports = {
throw new Error('This command must be run in online mode. Try running \'ipfs daemon\' first.')
}

ipfs.swarm.peers((err, res) => {
ipfs.swarm.peers((err, result) => {
if (err) {
throw err
}

res.forEach((addr) => {
console.log(addr.toString())
result.forEach((item) => {
console.log(item.addr.toString())
})
})
})
Expand Down
9 changes: 3 additions & 6 deletions src/core/components/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,13 @@ function prepareFile (self, file, callback) {
const bs58mh = multihashes.toB58String(file.multihash)
waterfall([
(cb) => self.object.get(file.multihash, cb),
(node, cb) => node.size((err, size) => {
if (err) {
return cb(err)
}
(node, cb) => {
cb(null, {
path: file.path || bs58mh,
hash: bs58mh,
size: size
size: node.size
})
})
}
], callback)
}

Expand Down
Loading