1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-19 18:05:32 +08:00

templates for block commands (updates #138)

This commit is contained in:
Henry
2014-10-13 20:31:14 +02:00
parent 8ede898517
commit 08bb6f149f
3 changed files with 102 additions and 0 deletions

44
core/commands/block.go Normal file
View File

@ -0,0 +1,44 @@
package commands
import (
"io"
"io/ioutil"
"os"
"github.com/jbenet/go-ipfs/blocks"
"github.com/jbenet/go-ipfs/core"
u "github.com/jbenet/go-ipfs/util"
)
func BlockGet(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
k := u.Key(args[0])
u.PErr("Getting block[%s]\n", k)
b, err := n.Blocks.GetBlock(k)
if err != nil {
return err
}
out.Write(b.Data)
return nil
}
func BlockPut(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
b := blocks.NewBlock(data)
u.PErr("Putting block[%s]\n", b.Key())
key, err := n.Blocks.AddBlock(b)
if err != nil {
return err
}
u.PErr("Done. Key: %s\n", key)
return nil
}