Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit f33b74f

Browse files
authoredOct 28, 2016
Merge pull request #398 from ipfs/awesome-ipld
Awesome IPLD Endeavour
2 parents 1d9647e + baa72d0 commit f33b74f

File tree

5 files changed

+84
-38
lines changed

5 files changed

+84
-38
lines changed
 

‎package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
"coverage-publish": "aegir-coverage publish"
1818
},
1919
"dependencies": {
20-
"async": "^2.0.1",
21-
"babel-runtime": "^6.11.6",
20+
"async": "^2.1.2",
21+
"babel-runtime": "^6.18.0",
2222
"bl": "^1.1.2",
2323
"bs58": "^3.0.0",
2424
"detect-node": "^2.0.3",
2525
"flatmap": "0.0.3",
26-
"glob": "^7.0.5",
27-
"ipfs-block": "^0.3.0",
28-
"ipfs-merkle-dag": "^0.7.1",
26+
"glob": "^7.1.1",
27+
"ipfs-block": "^0.4.0",
28+
"ipld-dag-pb": "^0.1.3",
2929
"is-ipfs": "^0.2.0",
3030
"isstream": "^0.1.2",
3131
"multiaddr": "^2.0.2",
@@ -34,7 +34,7 @@
3434
"peer-id": "^0.7.0",
3535
"peer-info": "^0.7.1",
3636
"promisify-es6": "^1.0.1",
37-
"qs": "^6.2.1",
37+
"qs": "^6.3.0",
3838
"streamifier": "^0.1.1",
3939
"tar-stream": "^1.5.2",
4040
"wreck": "^10.0.0"
@@ -47,17 +47,17 @@
4747
"url": "https://github.com/ipfs/js-ipfs-api"
4848
},
4949
"devDependencies": {
50-
"aegir": "^8.0.0",
50+
"aegir": "^8.1.2",
5151
"chai": "^3.5.0",
5252
"gulp": "^3.9.1",
53-
"hapi": "^15.0.2",
54-
"interface-ipfs-core": "^0.15.0",
53+
"hapi": "^15.2.0",
54+
"interface-ipfs-core": "^0.16.1",
5555
"ipfsd-ctl": "^0.16.0",
5656
"pre-commit": "^1.1.3",
57-
"socket.io": "^1.4.8",
58-
"socket.io-client": "^1.4.8",
57+
"socket.io": "^1.5.1",
58+
"socket.io-client": "^1.5.1",
5959
"stream-equal": "^0.1.8",
60-
"stream-http": "^2.3.1"
60+
"stream-http": "^2.4.0"
6161
},
6262
"pre-commit": [
6363
"lint",
@@ -103,4 +103,4 @@
103103
"url": "https://github.com/ipfs/js-ipfs-api/issues"
104104
},
105105
"homepage": "https://github.com/ipfs/js-ipfs-api"
106-
}
106+
}

‎src/add-to-dagnode-transform.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,29 @@ const map = require('async/map')
44
const getDagNode = require('./get-dagnode')
55

66
// transform { Hash: '...' } objects into { path: 'string', node: DAGNode }
7-
module.exports = function (err, res, send, done) {
7+
module.exports = (err, res, send, done) => {
88
if (err) {
99
return done(err)
1010
}
1111

12-
map(res, function map (entry, next) {
13-
getDagNode(send, entry.Hash, function (err, node) {
12+
map(res, (entry, next) => {
13+
getDagNode(send, entry.Hash, (err, node) => {
1414
if (err) {
1515
return next(err)
1616
}
17-
var obj = {
18-
path: entry.Name,
19-
hash: entry.Hash,
20-
size: node.size()
21-
}
22-
next(null, obj)
17+
node.size((err, size) => {
18+
if (err) {
19+
return next(err)
20+
}
21+
const obj = {
22+
path: entry.Name,
23+
hash: entry.Hash,
24+
size: size
25+
}
26+
next(null, obj)
27+
})
2328
})
24-
}, function (err, res) {
29+
}, (err, res) => {
2530
done(err, res)
2631
})
2732
}

‎src/api/block.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
const promisify = require('promisify-es6')
44
const bl = require('bl')
55
const Block = require('ipfs-block')
6+
const multihash = require('multihashes')
7+
const CID = require('cids')
68

79
module.exports = (send) => {
810
return {
911
get: promisify((args, opts, callback) => {
12+
// TODO this needs to be adjusted with the new go-ipfs http-api
13+
if (args && CID.isCID(args)) {
14+
args = multihash.toB58String(args.multihash)
15+
}
1016
if (typeof (opts) === 'function') {
1117
callback = opts
1218
opts = {}
1319
}
20+
1421
return send({
1522
path: 'block/get',
1623
args: args,
@@ -32,6 +39,11 @@ module.exports = (send) => {
3239
})
3340
}),
3441
stat: promisify((args, opts, callback) => {
42+
// TODO this needs to be adjusted with the new go-ipfs http-api
43+
if (args && CID.isCID(args)) {
44+
args = multihash.toB58String(args.multihash)
45+
}
46+
3547
if (typeof (opts) === 'function') {
3648
callback = opts
3749
opts = {}
@@ -50,7 +62,13 @@ module.exports = (send) => {
5062
})
5163
})
5264
}),
53-
put: promisify((block, callback) => {
65+
put: promisify((block, cid, callback) => {
66+
// TODO this needs to be adjusted with the new go-ipfs http-api
67+
if (typeof cid === 'function') {
68+
callback = cid
69+
cid = {}
70+
}
71+
5472
if (Array.isArray(block)) {
5573
const err = new Error('block.put() only accepts 1 file')
5674
return callback(err)

‎src/api/object.js

+36-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict'
22

3-
const DAGNode = require('ipfs-merkle-dag').DAGNode
4-
const DAGLink = require('ipfs-merkle-dag').DAGLink
3+
const dagPB = require('ipld-dag-pb')
4+
const DAGNode = dagPB.DAGNode
5+
const DAGLink = dagPB.DAGLink
56
const promisify = require('promisify-es6')
67
const bs58 = require('bs58')
78
const bl = require('bl')
@@ -93,21 +94,37 @@ module.exports = (send) => {
9394
obj = JSON.parse(obj.toString())
9495
}
9596
}
97+
9698
let node
99+
97100
if (obj.multihash) {
98101
node = obj
99102
} else if (options.enc === 'protobuf') {
100-
node = new DAGNode()
101-
node.unMarshal(obj)
103+
dagPB.util.deserialize(obj, (err, _node) => {
104+
if (err) {
105+
return callback(err)
106+
}
107+
node = _node
108+
next()
109+
})
110+
return
102111
} else {
103112
node = new DAGNode(obj.Data, obj.Links)
104113
}
105-
106-
if (node.toJSON().Hash !== result.Hash) {
107-
return callback(new Error('Stored object was different from constructed object'))
114+
next()
115+
116+
function next () {
117+
node.toJSON((err, nodeJSON) => {
118+
if (err) {
119+
return callback(err)
120+
}
121+
if (nodeJSON.Hash !== result.Hash) {
122+
return callback(new Error('Stored object was different from constructed object'))
123+
}
124+
125+
callback(null, node)
126+
})
108127
}
109-
110-
callback(null, node)
111128
})
112129
}),
113130
data: promisify((multihash, options, callback) => {
@@ -200,13 +217,19 @@ module.exports = (send) => {
200217
if (err) {
201218
return callback(err)
202219
}
220+
203221
const node = new DAGNode()
222+
node.toJSON((err, nodeJSON) => {
223+
if (err) {
224+
return callback(err)
225+
}
204226

205-
if (node.toJSON().Hash !== result.Hash) {
206-
return callback(new Error('Stored object was different from constructed object'))
207-
}
227+
if (nodeJSON.Hash !== result.Hash) {
228+
return callback(new Error('Stored object was different from constructed object'))
229+
}
208230

209-
callback(null, node)
231+
callback(null, node)
232+
})
210233
})
211234
}),
212235
patch: {

‎src/get-dagnode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const DAGNode = require('ipfs-merkle-dag').DAGNode
3+
const DAGNode = require('ipld-dag-pb').DAGNode
44
const bl = require('bl')
55
const parallel = require('async/parallel')
66

0 commit comments

Comments
 (0)