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

Commit

Permalink
object create
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Jan 28, 2016
1 parent 56f771b commit f90be15
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/cli/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = Command.extend({

run: (bool, json, key, value) => {
if (!key) {
throw new Error('argument \'key\' is required')
throw new Error("argument 'key' is required")
}

var node = new IPFS()
Expand Down
38 changes: 35 additions & 3 deletions src/ipfs-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

const defaultRepo = require('./default-repo')
// const bl = require('bl')
const MerkleDAG = require('ipfs-merkle-dag')
const BlockService = MerkleDAG.BlockService
// const Block = MerkleDAG.Block
const mDAG = require('ipfs-merkle-dag')
const BlockService = mDAG.BlockService
const Block = mDAG.Block

exports = module.exports = IPFS

Expand Down Expand Up @@ -152,4 +152,36 @@ function IPFS (repo) {
})
}
}

this.object = {
// named `new` in go-ipfs
create: (template, callback) => {
if (!callback) {
callback = template
}
var node = new mDAG.DAGNode()
var block = new Block(node.marshal())
bs.addBlock(block, function (err) {
if (err) {
return callback(err)
}
callback(null, {
Hash: block.key,
Size: node.size(),
Name: ''
})
})
},
patch: (multihash, options, callback) => {},
data: (multihash, callback) => {},
links: (multihash, callback) => {},
get: (multihash, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}
},
put: (multihash, options, callback) => {},
stat: (multihash, options, callback) => {}
}
}
2 changes: 1 addition & 1 deletion tests/test-cli/test-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('config', () => {
it('call config with no arguments', done => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'config'])
.run((err, stdout, exitcode) => {
const expected = 'error argument \'key\' is required'
const expected = "error argument 'key' is required"
expect(stdout[0]).to.equal(expected)
expect(err).to.not.exist
expect(exitcode).to.equal(1)
Expand Down
6 changes: 3 additions & 3 deletions tests/test-core/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const _ = require('lodash')
const repoContext = require.context('buffer!./../repo-example', true)

const idb = window.indexedDB ||
window.mozIndexedDB ||
window.webkitIndexedDB ||
window.msIndexedDB
window.mozIndexedDB ||
window.webkitIndexedDB ||
window.msIndexedDB

idb.deleteDatabase('ipfs')
idb.deleteDatabase('ipfs/blocks')
Expand Down
2 changes: 1 addition & 1 deletion tests/test-core/test-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('block', function () {

it('stat', function (done) {
const mh = new Buffer(base58
.decode('QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe'))
.decode('QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe'))
ipfs.block.stat(mh, (err, stats) => {
expect(err).to.not.exist
expect(stats.Key.equals(mh)).to.equal(true)
Expand Down
16 changes: 8 additions & 8 deletions tests/test-core/test-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ describe('config', () => {
})
})

// cli only feature built with show and replace
// it.skip('edit', done => {
// const ipfs = new IPFS()
// ipfs.config((err, config) => {
// expect(err).to.not.exist
// done()
// })
// })
// cli only feature built with show and replace
// it.skip('edit', done => {
// const ipfs = new IPFS()
// ipfs.config((err, config) => {
// expect(err).to.not.exist
// done()
// })
// })
})
86 changes: 86 additions & 0 deletions tests/test-core/test-object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* globals describe, before, it */

'use strict'

const expect = require('chai').expect
// const base58 = require('bs58')
const IPFS = require('../../src/ipfs-core')
// const Block = require('ipfs-merkle-dag').Block

// const isNode = !global.window

// TODO use arrow funtions again when https://github.com/webpack/webpack/issues/1944 is fixed
describe('object', function () {
var ipfs

before(function (done) {
ipfs = new IPFS()
done()
})

it('create', function (done) {
ipfs.object.create(function (err, obj) {
expect(err).to.not.exist
console.log(obj)
done()
})
})

it.skip('patch append-data', function (done) {

})

it.skip('patch add-link', function (done) {

})

it.skip('patch rm-link', function (done) {

})

it.skip('patch set-data', function (done) {

})

it.skip('patch append-data go-ipfs mDAG obj', function (done) {

})

it.skip('patch add-link go-ipfs mDAG obj', function (done) {

})

it.skip('patch rm-link go-ipfs mDAG obj', function (done) {

})

it.skip('patch set-data go-ipfs mDAG obj', function (done) {

})

it.skip('data', function (done) {

})

it.skip('links', function (done) {

})

it.skip('get', function (done) {

})

it.skip('get cycle', function (done) {
// 1. get a go-ipfs marshaled DAG Node
// 2. store it and fetch it again
// 3. check if still matches (ipfs-merkle-dag should not mangle it)
})

it.skip('put', function (done) {

})

it.skip('stat', function (done) {

})
})

0 comments on commit f90be15

Please sign in to comment.