This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feature object #63
Merged
Merged
feature object #63
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bf15330
object create
daviddias 6a3b889
get and put
daviddias 8780bf9
fix the tab thing https://github.com/ipfs/js-ipfs/pull/63#discussion-…
daviddias f28a0f3
links and stat
daviddias 80d098f
data
daviddias 0f57083
patch and all its methods
daviddias 3b4c53b
use webpack 2 to solve buffer issues
daviddias 8e4b058
apply CR comments
daviddias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,12 @@ | |
|
||
const defaultRepo = require('./default-repo') | ||
// const bl = require('bl') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
@@ -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 | ||
|
@@ -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) | ||
} | ||
|
@@ -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) | ||
}) | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...blocks/12203aa9/12203aa913048b2ef582d4ee2bf6eccad869e2ae1d9e41a2df4e086fe2e1403e8a5b.data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/ | ||
" wҢ���x�G�ܙ��}X���������yZdirect�T2 | ||
" �˧7Fw�}�|ɣ�*�#��'V>�|� recursive�T | ||
|
3 changes: 3 additions & 0 deletions
3
...blocks/122048b2/122048b220016f4051d7dd74315bf1ffcb1454f0dd7ae43df2dde01bef8a8bdae446.data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+10.5 KB
...blocks/122077d2/122077d2a2b0fc907805a547ea83dc99acff7d5806c086068cad8d9e820dd2f4795a.data
Binary file not shown.
Binary file added
BIN
+309 Bytes
...blocks/12209d6c/12209d6c2be50f706953479ab9df2ce3edca90b68053c00b3004b7f0accbe1e8eedf.data
Binary file not shown.
Binary file added
BIN
+10.6 KB
...blocks/1220b0ab/1220b0abba9f487a9f38ed23337532da45448e0cd0e21ec6a5dec62a51c54b4d51d1.data
Binary file not shown.
Binary file added
BIN
+10.6 KB
...blocks/1220b0cb/1220b0cba7371f11461f77081b947d837cc9a3b80e182ac123bbd427563e8b167c96.data
Binary file not shown.
115 changes: 115 additions & 0 deletions
115
...blocks/1220e586/1220e586199640e1a4c63fa38c5434b9e72dc99d23a391d3db5e1e42d00527241671.data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+10.5 KB
...blocks/1220f1c1/1220f1c121360796b1c031b0d8b58fd546ab06c601063224601337231b75401a31dd.data
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single quotes on the outside, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
expect(stdout[0]).to.equal(expected) | ||
expect(err).to.not.exist | ||
expect(exitcode).to.equal(1) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
// }) | ||
// }) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is
standard
codestyle thingsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's stupid :(
There was a problem hiding this comment.
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?