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

Commit 860cfd7

Browse files
committed
object create
1 parent 56f771b commit 860cfd7

File tree

7 files changed

+114
-17
lines changed

7 files changed

+114
-17
lines changed

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: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

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

99
exports = module.exports = IPFS
1010

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

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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* globals describe, before, it */
2+
3+
'use strict'
4+
5+
const expect = require('chai').expect
6+
// const base58 = require('bs58')
7+
const IPFS = require('../../src/ipfs-core')
8+
// const Block = require('ipfs-merkle-dag').Block
9+
10+
// const isNode = !global.window
11+
12+
// TODO use arrow funtions again when https://github.com/webpack/webpack/issues/1944 is fixed
13+
describe('object', function () {
14+
var ipfs
15+
16+
before(function (done) {
17+
ipfs = new IPFS()
18+
done()
19+
})
20+
21+
it('create', function (done) {
22+
ipfs.object.create(function (err, obj) {
23+
expect(err).to.not.exist
24+
console.log(obj)
25+
done()
26+
})
27+
})
28+
29+
it.skip('patch append-data', function (done) {
30+
31+
})
32+
33+
it.skip('patch add-link', function (done) {
34+
35+
})
36+
37+
it.skip('patch rm-link', function (done) {
38+
39+
})
40+
41+
it.skip('patch set-data', function (done) {
42+
43+
})
44+
45+
it.skip('data', function (done) {
46+
47+
})
48+
49+
it.skip('links', function (done) {
50+
51+
})
52+
53+
it.skip('get', function (done) {
54+
55+
})
56+
57+
it.skip('put', function (done) {
58+
59+
})
60+
61+
it.skip('stat', function (done) {
62+
63+
})
64+
})

0 commit comments

Comments
 (0)