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
634005a1
Commit
634005a1
authored
Oct 29, 2016
by
Jeromy Johnson
Committed by
GitHub
Oct 29, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3324 from ipfs/feat/block-cid-codec
allow cid format selection in block put command
parents
8d4fd80f
f68e1843
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
1 deletion
+57
-1
core/commands/block.go
core/commands/block.go
+42
-1
test/sharness/t0050-block.sh
test/sharness/t0050-block.sh
+15
-0
No files found.
core/commands/block.go
View file @
634005a1
...
...
@@ -10,7 +10,9 @@ import (
"github.com/ipfs/go-ipfs/blocks"
util
"github.com/ipfs/go-ipfs/blocks/blockstore/util"
cmds
"github.com/ipfs/go-ipfs/commands"
cid
"gx/ipfs/QmXfiyr2RWEXpVDdaYnD2HNiBk6UBddsvEP4RPfXb6nGqY/go-cid"
mh
"gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash"
u
"gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
)
...
...
@@ -113,6 +115,9 @@ It reads from stdin, and <key> is a base58 encoded multihash.
Arguments
:
[]
cmds
.
Argument
{
cmds
.
FileArg
(
"data"
,
true
,
false
,
"The data to be stored as an IPFS block."
)
.
EnableStdin
(),
},
Options
:
[]
cmds
.
Option
{
cmds
.
StringOption
(
"format"
,
"f"
,
"cid format for blocks to be created with."
)
.
Default
(
"v0"
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
if
err
!=
nil
{
...
...
@@ -138,7 +143,39 @@ It reads from stdin, and <key> is a base58 encoded multihash.
return
}
b
:=
blocks
.
NewBlock
(
data
)
format
,
_
,
_
:=
req
.
Option
(
"format"
)
.
String
()
var
pref
cid
.
Prefix
pref
.
MhType
=
mh
.
SHA2_256
pref
.
MhLength
=
-
1
pref
.
Version
=
1
switch
format
{
case
"cbor"
:
pref
.
Codec
=
cid
.
CBOR
case
"json"
:
pref
.
Codec
=
cid
.
JSON
case
"protobuf"
:
pref
.
Codec
=
cid
.
Protobuf
case
"raw"
:
pref
.
Codec
=
cid
.
Raw
case
"v0"
:
pref
.
Version
=
0
pref
.
Codec
=
cid
.
Protobuf
default
:
res
.
SetError
(
fmt
.
Errorf
(
"unrecognized format: %s"
,
format
),
cmds
.
ErrNormal
)
return
}
bcid
,
err
:=
pref
.
Sum
(
data
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
b
,
err
:=
blocks
.
NewBlockWithCid
(
data
,
bcid
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
log
.
Debugf
(
"BlockPut key: '%q'"
,
b
.
Cid
())
k
,
err
:=
n
.
Blocks
.
AddBlock
(
b
)
...
...
@@ -162,6 +199,10 @@ It reads from stdin, and <key> is a base58 encoded multihash.
}
func
getBlockForKey
(
req
cmds
.
Request
,
skey
string
)
(
blocks
.
Block
,
error
)
{
if
len
(
skey
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"zero length cid invalid"
)
}
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
if
err
!=
nil
{
return
nil
,
err
...
...
test/sharness/t0050-block.sh
View file @
634005a1
...
...
@@ -169,6 +169,21 @@ test_expect_success "multi-block 'ipfs block rm -q' produces no output" '
test ! -s block_rm_out
'
test_expect_success
"can set cid format on block put"
'
HASH=$(ipfs block put --format=protobuf ../t0051-object-data/testPut.pb)
'
test_expect_success
"created an object correctly!"
'
ipfs object get $HASH > obj_out &&
echo "{\"Links\":[],\"Data\":\"test json for sharness test\"}" > obj_exp &&
test_cmp obj_out obj_exp
'
test_expect_success
"block get output looks right"
'
ipfs block get $HASH > pb_block_out &&
test_cmp pb_block_out ../t0051-object-data/testPut.pb
'
#
# Misc tests
#
...
...
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