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

feature object #63

Merged
merged 8 commits into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"rimraf": "^2.4.4",
"standard": "^5.4.1",
"transform-loader": "^0.2.3",
"webpack": "diasdavid/webpack#81f5994"
"webpack": "^2.0.5-beta"
},
"dependencies": {
"bl": "^1.0.0",
Expand All @@ -67,7 +67,7 @@
"debug": "^2.2.0",
"hapi": "^12.0.0",
"ipfs-blocks": "^0.1.0",
"ipfs-merkle-dag": "^0.1.1",
"ipfs-merkle-dag": "^0.2.1",
"ipfs-repo": "^0.5.0",
"lodash.get": "^4.0.0",
"lodash.set": "^4.0.0",
Expand Down
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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is standard codestyle things

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's stupid :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe lint in a separate commit?

}

var node = new IPFS()
Expand Down
144 changes: 137 additions & 7 deletions src/ipfs-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

const defaultRepo = require('./default-repo')
// const bl = require('bl')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to keep this around?

// const MerkleDAG = require('ipfs-merkle-dag')
const blocks = require('ipfs-blocks')
const BlockService = blocks.BlockService
// const Block = MerkleDAG.Block
const Block = blocks.Block
const mDAG = require('ipfs-merkle-dag')
const DAGNode = mDAG.DAGNode
const DAGService = mDAG.DAGService

exports = module.exports = IPFS

Expand All @@ -17,7 +19,8 @@ function IPFS (repo) {
if (!repo) {
repo = defaultRepo()
}
const bs = new BlockService(repo)
const blockS = new BlockService(repo)
const dagS = new DAGService(blockS)

this.daemon = callback => {
// 1. read repo to get peer data
Expand Down Expand Up @@ -133,16 +136,16 @@ function IPFS (repo) {

this.block = {
get: (multihash, callback) => {
bs.getBlock(multihash, callback)
blockS.getBlock(multihash, callback)
},
put: (block, callback) => {
bs.addBlock(block, callback)
blockS.addBlock(block, callback)
},
del: (multihash, callback) => {
bs.deleteBlock(multihash, callback)
blockS.deleteBlock(multihash, callback)
},
stat: (multihash, callback) => {
bs.getBlock(multihash, (err, block) => {
blockS.getBlock(multihash, (err, block) => {
if (err) {
return callback(err)
}
Expand All @@ -153,4 +156,131 @@ function IPFS (repo) {
})
}
}

this.object = {
new: (template, callback) => {
if (!callback) {
callback = template
}
var node = new DAGNode()
var block = new Block(node.marshal())
blockS.addBlock(block, function (err) {
if (err) {
return callback(err)
}
callback(null, {
Hash: block.key,
Size: node.size(),
Name: ''
})
})
},
patch: {
appendData: (multihash, data, callback) => {
this.object.get(multihash, (err, obj) => {
if (err) { return callback(err) }
obj.data = Buffer.concat([obj.data, data])
dagS.add(obj, (err) => {
if (err) {
return callback(err)
}
callback(null, obj.multihash())
})
})
},
addLink: (multihash, link, callback) => {
this.object.get(multihash, (err, obj) => {
if (err) { return callback(err) }
obj.addRawLink(link)
dagS.add(obj, (err) => {
if (err) {
return callback(err)
}
callback(null, obj.multihash())
})
})
},
rmLink: (multihash, multihashLink, callback) => {
this.object.get(multihash, (err, obj) => {
if (err) { return callback(err) }
obj.links = obj.links.filter((link) => {
if (link.hash.equals(multihashLink)) {
return false
}
return true
})
dagS.add(obj, (err) => {
if (err) {
return callback(err)
}
callback(null, obj.multihash())
})
})
},
setData: (multihash, data, callback) => {
this.object.get(multihash, (err, obj) => {
if (err) { return callback(err) }
obj.data = data
dagS.add(obj, (err) => {
if (err) {
return callback(err)
}
callback(null, obj.multihash())
})
})
}
},
data: (multihash, callback) => {
this.object.get(multihash, (err, obj) => {
if (err) {
return callback(err)
}
callback(null, obj.data)
})
},
links: (multihash, callback) => {
this.object.get(multihash, (err, obj) => {
if (err) {
return callback(err)
}
callback(null, obj.links)
})
},
get: (multihash, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}
dagS.get(multihash, callback)
},
put: (dagNode, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}
dagS.add(dagNode, callback)
},
stat: (multihash, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}

this.object.get(multihash, (err, obj) => {
if (err) {
return callback(err)
}
var res = {
NumLinks: obj.links.length,
BlockSize: obj.marshal().length,
LinksSize: obj.links.reduce((prev, link) => {
return prev + link.size
}, 0),
DataSize: obj.data.length,
CumulativeSize: ''
}
callback(null, res)
})
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/
" wҢ���x�G�ܙ��}X���������yZdirect�T2
" �˧7Fw�}�|ɣ�*�#��'V>�|� recursive�T
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/
" ��!6���1�ص��F��2$`7#u@1�direct�T2
" ����Hz�8�#3u2�ED� ��ƥ��*Q�KMQ� recursive�T
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

��# 0.1 - Quick Start

This is a set of short examples with minimal explanation. It is meant as
a "quick start". Soon, we'll write a longer tour :-)


Add a file to ipfs:

echo "hello world" >hello
ipfs add hello


View it:

ipfs cat <the-hash-you-got-here>


Try a directory:

mkdir foo
mkdir foo/bar
echo "baz" > foo/baz
echo "baz" > foo/bar/baz
ipfs add -r foo


View things:

ipfs ls <the-hash-here>
ipfs ls <the-hash-here>/bar
ipfs cat <the-hash-here>/baz
ipfs cat <the-hash-here>/bar/baz
ipfs cat <the-hash-here>/bar
ipfs ls <the-hash-here>/baz


References:

ipfs refs <the-hash-here>
ipfs refs -r <the-hash-here>
ipfs refs --help


Get:

ipfs get <the-hash-here> -o foo2
diff foo foo2


Objects:

ipfs object get <the-hash-here>
ipfs object get <the-hash-here>/foo2
ipfs object --help


Pin + GC:

ipfs pin add <the-hash-here>
ipfs repo gc
ipfs ls <the-hash-here>
ipfs pin rm <the-hash-here>
ipfs repo gc


Daemon:

ipfs daemon (in another terminal)
ipfs id


Network:

(must be online)
ipfs swarm peers
ipfs id
ipfs cat <hash-of-remote-object>


Mount:

(warning: fuse is finicky!)
ipfs mount
cd /ipfs/<the-hash-here>
ls


Tool:

ipfs version
ipfs update
ipfs commands
ipfs config --help
open http://localhost:5001/webui


Browse:

webui:

http://localhost:5001/webui

video:

http://localhost:8080/ipfs/QmVc6zuAneKJzicnJpfrqCH9gSy6bz54JhcypfJYhGUFQu/play#/ipfs/QmTKZgRNwDNZwHtJSjCp6r5FYefzpULfy37JvMt9DwvXse

images:

http://localhost:8080/ipfs/QmZpc3HvfjEXvLWGQPWbHk3AjD5j8NEN4gmFN8Jmrd5g83/cs

markdown renderer app:

http://localhost:8080/ipfs/QmX7M9CiYXjVeFnkfVGf3y5ixTZ2ACeSGyL1vBJY1HvQPp/mdown
�
Expand Down
Binary file not shown.
Binary file added tests/repo-example/datastore/MANIFEST-000004
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test-cli/test-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('config', () => {
it('set a config key with invalid json', done => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'config', 'foo', '{"bar: 0}', '--json'])
.run((err, stdout, exitcode) => {
const expected = 'error invalid JSON provided'
const expected = 'error\tinvalid JSON provided'
expect(stdout[0]).to.equal(expected)
expect(err).to.not.exist
expect(exitcode).to.equal(1)
Expand All @@ -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\targument 'key' is required"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single quotes on the outside, \' on the inside (standard)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standard --format caused that change

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()
// })
// })
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's just delete this? it's all in git so we can bring it back if we need it.

Loading