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

Commit bf15330

Browse files
committed
object create
1 parent 957fa7d commit bf15330

File tree

8 files changed

+140
-16
lines changed

8 files changed

+140
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"debug": "^2.2.0",
6868
"hapi": "^12.0.0",
6969
"ipfs-blocks": "^0.1.0",
70-
"ipfs-merkle-dag": "^0.1.1",
70+
"ipfs-merkle-dag": "^0.2.0",
7171
"ipfs-repo": "^0.5.0",
7272
"lodash.get": "^4.0.0",
7373
"lodash.set": "^4.0.0",

src/cli/commands/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = Command.extend({
2424

2525
run: (bool, json, key, value) => {
2626
if (!key) {
27-
throw new Error('argument \'key\' is required')
27+
throw new Error("argument 'key' is required")
2828
}
2929

3030
var node = new IPFS()

src/ipfs-core/index.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
const defaultRepo = require('./default-repo')
44
// const bl = require('bl')
5-
// const MerkleDAG = require('ipfs-merkle-dag')
65
const blocks = require('ipfs-blocks')
76
const BlockService = blocks.BlockService
7+
const Block = blocks.Block
88
// const Block = MerkleDAG.Block
9+
const mDAG = require('ipfs-merkle-dag')
910

1011
exports = module.exports = IPFS
1112

@@ -153,4 +154,36 @@ function IPFS (repo) {
153154
})
154155
}
155156
}
157+
158+
this.object = {
159+
// named `new` in go-ipfs
160+
create: (template, callback) => {
161+
if (!callback) {
162+
callback = template
163+
}
164+
var node = new mDAG.DAGNode()
165+
var block = new Block(node.marshal())
166+
bs.addBlock(block, function (err) {
167+
if (err) {
168+
return callback(err)
169+
}
170+
callback(null, {
171+
Hash: block.key,
172+
Size: node.size(),
173+
Name: ''
174+
})
175+
})
176+
},
177+
patch: (multihash, options, callback) => {},
178+
data: (multihash, callback) => {},
179+
links: (multihash, callback) => {},
180+
get: (multihash, options, callback) => {
181+
if (typeof options === 'function') {
182+
callback = options
183+
options = {}
184+
}
185+
},
186+
put: (multihash, options, callback) => {},
187+
stat: (multihash, options, callback) => {}
188+
}
156189
}

tests/test-cli/test-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('config', () => {
7777
it('call config with no arguments', done => {
7878
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'config'])
7979
.run((err, stdout, exitcode) => {
80-
const expected = 'error argument \'key\' is required'
80+
const expected = "error argument 'key' is required"
8181
expect(stdout[0]).to.equal(expected)
8282
expect(err).to.not.exist
8383
expect(exitcode).to.equal(1)

tests/test-core/browser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ const _ = require('lodash')
77
const repoContext = require.context('buffer!./../repo-example', true)
88

99
const idb = window.indexedDB ||
10-
window.mozIndexedDB ||
11-
window.webkitIndexedDB ||
12-
window.msIndexedDB
10+
window.mozIndexedDB ||
11+
window.webkitIndexedDB ||
12+
window.msIndexedDB
1313

1414
idb.deleteDatabase('ipfs')
1515
idb.deleteDatabase('ipfs/blocks')

tests/test-core/test-block.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('block', function () {
6161

6262
it('stat', function (done) {
6363
const mh = new Buffer(base58
64-
.decode('QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe'))
64+
.decode('QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe'))
6565
ipfs.block.stat(mh, (err, stats) => {
6666
expect(err).to.not.exist
6767
expect(stats.Key.equals(mh)).to.equal(true)

tests/test-core/test-config.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ describe('config', () => {
9090
})
9191
})
9292

93-
// cli only feature built with show and replace
94-
// it.skip('edit', done => {
95-
// const ipfs = new IPFS()
96-
// ipfs.config((err, config) => {
97-
// expect(err).to.not.exist
98-
// done()
99-
// })
100-
// })
93+
// cli only feature built with show and replace
94+
// it.skip('edit', done => {
95+
// const ipfs = new IPFS()
96+
// ipfs.config((err, config) => {
97+
// expect(err).to.not.exist
98+
// done()
99+
// })
100+
// })
101101
})

tests/test-core/test-object.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/* globals describe, before, it */
2+
3+
'use strict'
4+
5+
const expect = require('chai').expect
6+
const IPFS = require('../../src/ipfs-core')
7+
const bs58 = require('bs58')
8+
// const Block = require('ipfs-merkle-dag').Block
9+
10+
// TODO use arrow funtions again when https://github.com/webpack/webpack/issues/1944 is fixed
11+
describe('object', function () {
12+
var ipfs
13+
14+
before(function (done) {
15+
ipfs = new IPFS()
16+
done()
17+
})
18+
19+
it('create', function (done) {
20+
ipfs.object.create(function (err, obj) {
21+
expect(err).to.not.exist
22+
expect(obj).to.have.property('Size')
23+
expect(obj.Size).to.equal(0)
24+
expect(obj).to.have.property('Name')
25+
expect(obj.Name).to.equal('')
26+
expect(obj).to.have.property('Hash')
27+
expect(bs58.encode(obj.Hash).toString())
28+
.to.equal('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')
29+
expect(obj.Size).to.equal(0)
30+
done()
31+
})
32+
})
33+
34+
it.skip('patch append-data', function (done) {
35+
36+
})
37+
38+
it.skip('patch add-link', function (done) {
39+
40+
})
41+
42+
it.skip('patch rm-link', function (done) {
43+
44+
})
45+
46+
it.skip('patch set-data', function (done) {
47+
48+
})
49+
50+
it.skip('patch append-data go-ipfs mDAG obj', function (done) {
51+
52+
})
53+
54+
it.skip('patch add-link go-ipfs mDAG obj', function (done) {
55+
56+
})
57+
58+
it.skip('patch rm-link go-ipfs mDAG obj', function (done) {
59+
60+
})
61+
62+
it.skip('patch set-data go-ipfs mDAG obj', function (done) {
63+
64+
})
65+
66+
it.skip('data', function (done) {
67+
68+
})
69+
70+
it.skip('links', function (done) {
71+
72+
})
73+
74+
it.skip('get', function (done) {
75+
76+
})
77+
78+
it.skip('get cycle', function (done) {
79+
// 1. get a go-ipfs marshaled DAG Node
80+
// 2. store it and fetch it again
81+
// 3. check if still matches (ipfs-merkle-dag should not mangle it)
82+
})
83+
84+
it.skip('put', function (done) {
85+
86+
})
87+
88+
it.skip('stat', function (done) {
89+
90+
})
91+
})

0 commit comments

Comments
 (0)