-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added block cmd #165
Merged
Merged
added block cmd #165
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
08bb6f1
templates for block commands (updates #138)
cryptix f93732a
added block get and put commands to daemon
cryptix 5b635bb
removed old examples from block help
cryptix 4abba7b
put has no key argument (it's derived from the valfile)
cryptix 073ec11
fixed BlockGet and cleaned up logging
cryptix a6630c8
display key if BlockPut is successful
cryptix f613af4
updated help for block commands
cryptix 03e42d8
added TODO about reading from io.Reader arg
cryptix 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 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,47 @@ | ||
package main | ||
|
||
import ( | ||
flag "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag" | ||
commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander" | ||
"github.com/jbenet/go-ipfs/core/commands" | ||
) | ||
|
||
var cmdIpfsBlock = &commander.Command{ | ||
UsageLine: "block", | ||
Short: "get/put **raw** ipfs blocks", | ||
Long: `ipfs block (get|put) - get/put **raw** ipfs blocks. | ||
|
||
ipfs block get <key> > valfile - get block of <key> and write it to valfile | ||
ipfs block put < valfile - saves the conents of valfile and returns it's <key> | ||
`, | ||
// Run: blockGetCmd, | ||
Subcommands: []*commander.Command{ | ||
cmdIpfsBlockGet, | ||
cmdIpfsBlockPut, | ||
}, | ||
Flag: *flag.NewFlagSet("ipfs-block", flag.ExitOnError), | ||
} | ||
|
||
var cmdIpfsBlockGet = &commander.Command{ | ||
UsageLine: "get", | ||
Short: "get a raw ipfs block", | ||
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. UsageLine: "get <key>"
Short: "get and output block named by <key>"
Long: `ipfs get <key> - get and output block named by <key>
ipfs block get is a plumbing command for retreiving raw ipfs blocks.
It outputs to stdout, and <key> is a base58 encoded multihash.
` |
||
Run: makeCommand(command{ | ||
name: "blockGet", | ||
args: 1, | ||
flags: nil, | ||
online: true, | ||
cmdFn: commands.BlockGet, | ||
}), | ||
} | ||
|
||
var cmdIpfsBlockPut = &commander.Command{ | ||
UsageLine: "put", | ||
Short: "put a raw ipfs block", | ||
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. UsageLine: "put"
Short: "store stdin as a block, outputs <key>"
Long: `ipfs put - store stdin as a block, outputs <key>
ipfs block put is a plumbing command for storing raw ipfs blocks.
It reads from stding, and <key> is a base58 encoded multihash.
` |
||
Run: makeCommand(command{ | ||
name: "blockPut", | ||
args: 0, | ||
flags: nil, | ||
online: true, | ||
cmdFn: commands.BlockPut, | ||
}), | ||
} |
This file contains 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 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,55 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
|
||
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash" | ||
"github.com/jbenet/go-ipfs/blocks" | ||
"github.com/jbenet/go-ipfs/core" | ||
u "github.com/jbenet/go-ipfs/util" | ||
) | ||
|
||
// BlockGet retrives a raw ipfs block from the node's BlockService | ||
func BlockGet(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error { | ||
|
||
if !u.IsValidHash(args[0]) { | ||
return fmt.Errorf("block get: not a valid hash") | ||
} | ||
|
||
h, err := mh.FromB58String(args[0]) | ||
if err != nil { | ||
return fmt.Errorf("block get: %v", err) | ||
} | ||
|
||
k := u.Key(h) | ||
log.Debug("BlockGet key: '%q'", k) | ||
b, err := n.Blocks.GetBlock(k) | ||
if err != nil { | ||
return fmt.Errorf("block get: %v", err) | ||
} | ||
|
||
_, err = out.Write(b.Data) | ||
return err | ||
} | ||
|
||
// BlockPut reads everything from conn and saves the data to the nodes BlockService | ||
func BlockPut(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error { | ||
data, err := ioutil.ReadAll(os.Stdin) | ||
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. can you add: // TODO: this should read from an io.Reader arg |
||
if err != nil { | ||
return err | ||
} | ||
|
||
b := blocks.NewBlock(data) | ||
log.Debug("BlockPut key: '%q'", b.Key()) | ||
|
||
k, err := n.Blocks.AddBlock(b) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Fprintf(out, "added as '%s'\n", k) | ||
|
||
return nil | ||
} |
This file contains 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
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.
Let's do: