Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
707f7018
Commit
707f7018
authored
Oct 14, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #165 from cryptix/blockCmd
added block cmd
parents
1a4bd39f
03e42d8e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
119 additions
and
0 deletions
+119
-0
cmd/ipfs/block.go
cmd/ipfs/block.go
+58
-0
cmd/ipfs/ipfs.go
cmd/ipfs/ipfs.go
+1
-0
core/commands/block.go
core/commands/block.go
+56
-0
daemon/daemon.go
daemon/daemon.go
+4
-0
No files found.
cmd/ipfs/block.go
0 → 100644
View file @
707f7018
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
:
"manipulate raw ipfs blocks"
,
Long
:
`ipfs block - manipulate raw ipfs blocks
ipfs block get <key> - get and output block named by <key>
ipfs block put - store stdin as a block, outputs <key>
ipfs block is a plumbing command used to manipulate raw ipfs blocks.
Reads from stdin or writes to stdout, and <key> is a base58 encoded
multihash.`
,
// Run: blockGetCmd,
Subcommands
:
[]
*
commander
.
Command
{
cmdIpfsBlockGet
,
cmdIpfsBlockPut
,
},
Flag
:
*
flag
.
NewFlagSet
(
"ipfs-block"
,
flag
.
ExitOnError
),
}
var
cmdIpfsBlockGet
=
&
commander
.
Command
{
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
:
"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
,
}),
}
cmd/ipfs/ipfs.go
View file @
707f7018
...
...
@@ -62,6 +62,7 @@ Use "ipfs help <command>" for more information about a command.
cmdIpfsName
,
cmdIpfsBootstrap
,
cmdIpfsDiag
,
cmdIpfsBlock
,
},
Flag
:
*
flag
.
NewFlagSet
(
"ipfs"
,
flag
.
ExitOnError
),
}
...
...
core/commands/block.go
0 → 100644
View file @
707f7018
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
{
// TODO: this should read from an io.Reader arg
data
,
err
:=
ioutil
.
ReadAll
(
os
.
Stdin
)
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
}
daemon/daemon.go
View file @
707f7018
...
...
@@ -133,6 +133,10 @@ func (dl *DaemonListener) handleConnection(conn manet.Conn) {
err
=
commands
.
Resolve
(
dl
.
node
,
command
.
Args
,
command
.
Opts
,
conn
)
case
"diag"
:
err
=
commands
.
Diag
(
dl
.
node
,
command
.
Args
,
command
.
Opts
,
conn
)
case
"blockGet"
:
err
=
commands
.
BlockGet
(
dl
.
node
,
command
.
Args
,
command
.
Opts
,
conn
)
case
"blockPut"
:
err
=
commands
.
BlockPut
(
dl
.
node
,
command
.
Args
,
command
.
Opts
,
conn
)
default
:
err
=
fmt
.
Errorf
(
"Invalid Command: '%s'"
,
command
.
Command
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment