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

Commit 33b0f18

Browse files
committed
object create
1 parent 957fa7d commit 33b0f18

File tree

7 files changed

+138
-15
lines changed

7 files changed

+138
-15
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: 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: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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('Hash')
23+
expect(obj).to.have.property('Size')
24+
expect(obj).to.have.property('Name')
25+
// depends on https://github.com/ipfs/go-ipfs/issues/2271
26+
// expect(bs58.encode(obj.Hash).toString())
27+
// .to.equal('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')
28+
expect(obj.Size).to.equal(2)
29+
done()
30+
})
31+
})
32+
33+
it.skip('patch append-data', function (done) {
34+
35+
})
36+
37+
it.skip('patch add-link', function (done) {
38+
39+
})
40+
41+
it.skip('patch rm-link', function (done) {
42+
43+
})
44+
45+
it.skip('patch set-data', function (done) {
46+
47+
})
48+
49+
it.skip('patch append-data go-ipfs mDAG obj', function (done) {
50+
51+
})
52+
53+
it.skip('patch add-link go-ipfs mDAG obj', function (done) {
54+
55+
})
56+
57+
it.skip('patch rm-link go-ipfs mDAG obj', function (done) {
58+
59+
})
60+
61+
it.skip('patch set-data go-ipfs mDAG obj', function (done) {
62+
63+
})
64+
65+
it.skip('data', function (done) {
66+
67+
})
68+
69+
it.skip('links', function (done) {
70+
71+
})
72+
73+
it.skip('get', function (done) {
74+
75+
})
76+
77+
it.skip('get cycle', function (done) {
78+
// 1. get a go-ipfs marshaled DAG Node
79+
// 2. store it and fetch it again
80+
// 3. check if still matches (ipfs-merkle-dag should not mangle it)
81+
})
82+
83+
it.skip('put', function (done) {
84+
85+
})
86+
87+
it.skip('stat', function (done) {
88+
89+
})
90+
})

0 commit comments

Comments
 (0)