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

Commit 59e4958

Browse files
authored
Merge pull request #78 from ipfs/awesome-ipld
Awesome IPLD endeavour
2 parents 3fdad1c + 4281d6f commit 59e4958

File tree

5 files changed

+659
-337
lines changed

5 files changed

+659
-337
lines changed

API/dag/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
dag API
2+
=======
3+
4+
#### `dag.put`
5+
6+
> Store an IPLD format node
7+
8+
##### `Go` **WIP**
9+
10+
##### `JavaScript` - ipfs.dag.put(dagNode, formatMulticodec, hashAlg, callback)
11+
12+
`dagNode` - a DAG node that follows one of the supported IPLD formats.
13+
14+
`formatMulticodec` - The IPLD format multicodec.
15+
16+
`hashAlg` - The hash algorithm to be used over the serialized dagNode.
17+
18+
`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful.
19+
20+
If no `callback` is passed, a [promise][] is returned.
21+
22+
#### `dag.get`
23+
24+
> Retrieve an IPLD format node
25+
26+
##### `Go` **WIP**
27+
28+
##### `JavaScript` - ipfs.object.get(cid, callback)
29+
30+
`cid` is a [CID][https://github.com/ipfs/js-cid] instance.
31+
32+
`callback` must follow `function (err, dagNode) {}` signature, where `err` is an error if the operation was not successful and `dagNode` is the IPLD format DAG node retrieved.
33+
34+
If no `callback` is passed, a [promise][] is returned.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@
2828
},
2929
"homepage": "https://github.com/ipfs/interface-ipfs-core#readme",
3030
"dependencies": {
31+
"async": "^2.1.2",
3132
"bl": "^1.1.2",
3233
"bs58": "^3.0.0",
3334
"chai": "^3.5.0",
34-
"concat-stream": "^1.5.1",
35+
"concat-stream": "^1.5.2",
3536
"detect-node": "^2.0.3",
36-
"ipfs-block": "^0.3.0",
37-
"ipfs-merkle-dag": "^0.7.0",
37+
"ipfs-block": "^0.4.0",
38+
"ipld-dag-pb": "^0.1.3",
3839
"multihashes": "^0.2.2",
39-
"readable-stream": "1.1.13",
40-
"run-series": "^1.1.4"
40+
"readable-stream": "1.1.13"
4141
},
4242
"devDependencies": {
43-
"aegir": "^8.0.0"
43+
"aegir": "^8.1.2"
4444
},
4545
"contributors": [
4646
"David Dias <daviddias.p@gmail.com>",
@@ -51,4 +51,4 @@
5151
"greenkeeperio-bot <support@greenkeeper.io>",
5252
"nginnever <ginneversource@gmail.com>"
5353
]
54-
}
54+
}

src/block.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
const expect = require('chai').expect
77
const Block = require('ipfs-block')
88
const multihash = require('multihashes')
9+
const CID = require('cids')
910

1011
module.exports = (common) => {
1112
describe('.block', () => {
@@ -34,23 +35,37 @@ module.exports = (common) => {
3435
describe('callback API', () => {
3536
it('.put a buffer', (done) => {
3637
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
38+
const cid = new CID(expectedHash)
3739
const blob = Buffer('blorb')
3840

39-
ipfs.block.put(blob, (err, block) => {
41+
ipfs.block.put(blob, cid, (err, block) => {
4042
expect(err).to.not.exist
41-
expect(block.key).to.eql(multihash.fromB58String(expectedHash))
43+
expect(block.key('sha2-256')).to.eql(multihash.fromB58String(expectedHash))
4244
expect(block).to.have.a.property('data', blob)
4345
done()
4446
})
4547
})
4648

4749
it('.put a block', (done) => {
50+
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
51+
const cid = new CID(expectedHash)
52+
const blob = new Block(new Buffer('blorb'))
53+
54+
ipfs.block.put(blob, cid, (err, block) => {
55+
expect(err).to.not.exist
56+
expect(block.key('sha2-256')).to.eql(multihash.fromB58String(expectedHash))
57+
expect(block.data).to.eql(new Buffer('blorb'))
58+
done()
59+
})
60+
})
61+
62+
it('.put a block (without using CID, legacy mode)', (done) => {
4863
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
4964
const blob = new Block(new Buffer('blorb'))
5065

5166
ipfs.block.put(blob, (err, block) => {
5267
expect(err).to.not.exist
53-
expect(block.key).to.eql(multihash.fromB58String(expectedHash))
68+
expect(block.key('sha2-256')).to.eql(multihash.fromB58String(expectedHash))
5469
expect(block.data).to.eql(new Buffer('blorb'))
5570
done()
5671
})
@@ -59,26 +74,39 @@ module.exports = (common) => {
5974
it('.put error with array of blocks', () => {
6075
const blob = Buffer('blorb')
6176

62-
ipfs.block.put([blob, blob], (err) => {
77+
ipfs.block.put([blob, blob], 'fake cids', (err) => {
6378
expect(err).to.be.an.instanceof(Error)
6479
})
6580
})
6681

6782
it('block.get', (done) => {
6883
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
84+
const cid = new CID(hash)
85+
86+
ipfs.block.get(cid, (err, block) => {
87+
expect(err).to.not.exist
88+
expect(block.key('sha2-256')).to.eql(cid.multihash)
89+
expect(block.data).to.eql(new Buffer('blorb'))
90+
done()
91+
})
92+
})
93+
94+
it('block.get (without using CID, legacy mode)', (done) => {
95+
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
6996

7097
ipfs.block.get(hash, (err, block) => {
7198
expect(err).to.not.exist
72-
expect(block.key).to.eql(multihash.fromB58String(hash))
99+
expect(block.key('sha2-256')).to.eql(multihash.fromB58String(hash))
73100
expect(block.data).to.eql(new Buffer('blorb'))
74101
done()
75102
})
76103
})
77104

78105
it('block.stat', (done) => {
79106
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
107+
const cid = new CID(hash)
80108

81-
ipfs.block.stat(hash, (err, stats) => {
109+
ipfs.block.stat(cid, (err, stats) => {
82110
expect(err).to.not.exist
83111
expect(stats).to.have.property('key')
84112
expect(stats).to.have.property('size')

0 commit comments

Comments
 (0)