Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
7be8475c
提交
7be8475c
authored
5月 14, 2019
作者:
Łukasz Magiera
提交者:
Steven Allen
6月 03, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
block cmd: allow adding multiple blocks at once
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
ff3efe84
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
39 行增加
和
16 行删除
+39
-16
block.go
core/commands/block.go
+26
-16
t0050-block.sh
test/sharness/t0050-block.sh
+13
-0
没有找到文件。
core/commands/block.go
浏览文件 @
7be8475c
...
...
@@ -6,6 +6,8 @@ import (
"io"
"os"
files
"github.com/ipfs/go-ipfs-files"
util
"github.com/ipfs/go-ipfs/blocks/blockstoreutil"
cmdenv
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
...
...
@@ -129,7 +131,7 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
},
Arguments
:
[]
cmds
.
Argument
{
cmds
.
FileArg
(
"data"
,
true
,
fals
e
,
"The data to be stored as an IPFS block."
)
.
EnableStdin
(),
cmds
.
FileArg
(
"data"
,
true
,
tru
e
,
"The data to be stored as an IPFS block."
)
.
EnableStdin
(),
},
Options
:
[]
cmds
.
Option
{
cmds
.
StringOption
(
blockFormatOptionName
,
"f"
,
"cid format for blocks to be created with."
),
...
...
@@ -143,11 +145,6 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
return
err
}
file
,
err
:=
cmdenv
.
GetFileArg
(
req
.
Files
.
Entries
())
if
err
!=
nil
{
return
err
}
mhtype
,
_
:=
req
.
Options
[
mhtypeOptionName
]
.
(
string
)
mhtval
,
ok
:=
mh
.
Names
[
mhtype
]
if
!
ok
{
...
...
@@ -170,18 +167,31 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
pin
,
_
:=
req
.
Options
[
pinOptionName
]
.
(
bool
)
p
,
err
:=
api
.
Block
()
.
Put
(
req
.
Context
,
file
,
options
.
Block
.
Hash
(
mhtval
,
mhlen
),
options
.
Block
.
Format
(
format
),
options
.
Block
.
Pin
(
pin
))
if
err
!=
nil
{
return
err
it
:=
req
.
Files
.
Entries
()
for
it
.
Next
()
{
file
:=
files
.
FileFromEntry
(
it
)
if
file
==
nil
{
return
errors
.
New
(
"expected a file"
)
}
p
,
err
:=
api
.
Block
()
.
Put
(
req
.
Context
,
file
,
options
.
Block
.
Hash
(
mhtval
,
mhlen
),
options
.
Block
.
Format
(
format
),
options
.
Block
.
Pin
(
pin
))
if
err
!=
nil
{
return
err
}
err
=
res
.
Emit
(
&
BlockStat
{
Key
:
p
.
Path
()
.
Cid
()
.
String
(),
Size
:
p
.
Size
(),
})
if
err
!=
nil
{
return
err
}
}
return
cmds
.
EmitOnce
(
res
,
&
BlockStat
{
Key
:
p
.
Path
()
.
Cid
()
.
String
(),
Size
:
p
.
Size
(),
})
return
it
.
Err
()
},
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
bs
*
BlockStat
)
error
{
...
...
test/sharness/t0050-block.sh
浏览文件 @
7be8475c
...
...
@@ -11,6 +11,7 @@ test_description="Test block command"
test_init_ipfs
HASH
=
"QmRKqGMAM6EZngbpjSqrvYzq5Qd8b1bSWymjSUY9zQSNDk"
HASHB
=
"QmdnpnsaEj69isdw5sNzp3h3HkaDz7xKq7BmvFFBzNr5e7"
#
# "block put tests"
...
...
@@ -26,6 +27,18 @@ test_expect_success "'ipfs block put' output looks good" '
test_cmp expected_out actual_out
'
test_expect_success
"'ipfs block put' with 2 files succeeds"
'
echo "Hello Mars!" > a &&
echo "Hello Venus!" > b &&
ipfs block put a b >actual_out
'
test_expect_success
"'ipfs block put' output looks good"
'
echo "$HASH" >expected_out &&
echo "$HASHB" >>expected_out &&
test_cmp expected_out actual_out
'
#
# "block get" tests
#
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论