Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
cf6e3219
提交
cf6e3219
authored
12月 07, 2016
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cmd/block: add selection of multihash parameters to block put command
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
上级
24d35f3c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
32 行增加
和
3 行删除
+32
-3
block.go
core/commands/block.go
+19
-3
t0050-block.sh
test/sharness/t0050-block.sh
+13
-0
没有找到文件。
core/commands/block.go
浏览文件 @
cf6e3219
...
...
@@ -117,6 +117,8 @@ It reads from stdin, and <key> is a base58 encoded multihash.
},
Options
:
[]
cmds
.
Option
{
cmds
.
StringOption
(
"format"
,
"f"
,
"cid format for blocks to be created with."
)
.
Default
(
"v0"
),
cmds
.
StringOption
(
"mhtype"
,
"multihash hash function"
)
.
Default
(
"sha2-256"
),
cmds
.
IntOption
(
"mhlen"
,
"multihash hash length"
)
.
Default
(
-
1
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
...
...
@@ -143,11 +145,10 @@ It reads from stdin, and <key> is a base58 encoded multihash.
return
}
format
,
_
,
_
:=
req
.
Option
(
"format"
)
.
String
()
var
pref
cid
.
Prefix
pref
.
MhType
=
mh
.
SHA2_256
pref
.
MhLength
=
-
1
pref
.
Version
=
1
format
,
_
,
_
:=
req
.
Option
(
"format"
)
.
String
()
switch
format
{
case
"cbor"
:
pref
.
Codec
=
cid
.
DagCBOR
...
...
@@ -163,6 +164,21 @@ It reads from stdin, and <key> is a base58 encoded multihash.
return
}
mhtype
,
_
,
_
:=
req
.
Option
(
"mhtype"
)
.
String
()
mhtval
,
ok
:=
mh
.
Names
[
mhtype
]
if
!
ok
{
res
.
SetError
(
fmt
.
Errorf
(
"unrecognized multihash function: %s"
,
mhtype
),
cmds
.
ErrNormal
)
return
}
pref
.
MhType
=
mhtval
mhlen
,
_
,
err
:=
req
.
Option
(
"mhlen"
)
.
Int
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
pref
.
MhLength
=
mhlen
bcid
,
err
:=
pref
.
Sum
(
data
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
...
...
test/sharness/t0050-block.sh
浏览文件 @
cf6e3219
...
...
@@ -184,6 +184,19 @@ test_expect_success "block get output looks right" '
test_cmp pb_block_out ../t0051-object-data/testPut.pb
'
test_expect_success
"can set multihash type and length on block put"
'
HASH=$(echo "foooo" | ipfs block put --format=raw --mhtype=sha3 --mhlen=16)
'
test_expect_success
"output looks good"
'
test "z25ScPysKoxJBcPxczn9NvuHiZU5" = "$HASH"
'
test_expect_success
"can read block with different hash"
'
ipfs block get $HASH > blk_get_out &&
echo "foooo" > blk_get_exp &&
test_cmp blk_get_exp blk_get_out
'
#
# Misc tests
#
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论