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-dms3
Commits
08bb6f14
Commit
08bb6f14
authored
10 years ago
by
Henry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
templates for block commands (updates #138)
parent
8ede8985
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
0 deletions
+102
-0
cmd/ipfs/block.go
cmd/ipfs/block.go
+57
-0
cmd/ipfs/ipfs.go
cmd/ipfs/ipfs.go
+1
-0
core/commands/block.go
core/commands/block.go
+44
-0
No files found.
cmd/ipfs/block.go
0 → 100644
View file @
08bb6f14
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 <key> < valfile - pipe valfile to block <key>
Examples:
Get the value of the 'datastore.path' key:
ipfs config datastore.path
Set the value of the 'datastore.path' key:
ipfs config datastore.path ~/.go-ipfs/datastore
`
,
// Run: blockGetCmd,
Subcommands
:
[]
*
commander
.
Command
{
cmdIpfsBlockGet
,
cmdIpfsBlockPut
,
},
Flag
:
*
flag
.
NewFlagSet
(
"ipfs-block"
,
flag
.
ExitOnError
),
}
var
cmdIpfsBlockGet
=
&
commander
.
Command
{
UsageLine
:
"get"
,
Short
:
"get a row ipfs block"
,
Run
:
makeCommand
(
command
{
name
:
"get"
,
args
:
1
,
flags
:
nil
,
online
:
true
,
cmdFn
:
commands
.
BlockGet
,
}),
}
var
cmdIpfsBlockPut
=
&
commander
.
Command
{
UsageLine
:
"put"
,
Short
:
"put a row ipfs block"
,
Run
:
makeCommand
(
command
{
name
:
"put"
,
args
:
1
,
flags
:
nil
,
online
:
true
,
cmdFn
:
commands
.
BlockPut
,
}),
}
This diff is collapsed.
Click to expand it.
cmd/ipfs/ipfs.go
View file @
08bb6f14
...
...
@@ -62,6 +62,7 @@ Use "ipfs help <command>" for more information about a command.
cmdIpfsName
,
cmdIpfsBootstrap
,
cmdIpfsDiag
,
cmdIpfsBlock
,
},
Flag
:
*
flag
.
NewFlagSet
(
"ipfs"
,
flag
.
ExitOnError
),
}
...
...
This diff is collapsed.
Click to expand it.
core/commands/block.go
0 → 100644
View file @
08bb6f14
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
}
This diff is collapsed.
Click to expand it.
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