Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
f68e1843
提交
f68e1843
authored
10月 18, 2016
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow cid format selection in block put command
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
上级
1c6e84ce
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
57 行增加
和
6 行删除
+57
-6
block.go
core/commands/block.go
+42
-6
t0050-block.sh
test/sharness/t0050-block.sh
+15
-0
没有找到文件。
core/commands/block.go
浏览文件 @
f68e1843
...
@@ -2,7 +2,6 @@ package commands
...
@@ -2,7 +2,6 @@ package commands
import
(
import
(
"bytes"
"bytes"
"errors"
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
...
@@ -11,7 +10,9 @@ import (
...
@@ -11,7 +10,9 @@ import (
"github.com/ipfs/go-ipfs/blocks"
"github.com/ipfs/go-ipfs/blocks"
util
"github.com/ipfs/go-ipfs/blocks/blockstore/util"
util
"github.com/ipfs/go-ipfs/blocks/blockstore/util"
cmds
"github.com/ipfs/go-ipfs/commands"
cmds
"github.com/ipfs/go-ipfs/commands"
cid
"gx/ipfs/QmXfiyr2RWEXpVDdaYnD2HNiBk6UBddsvEP4RPfXb6nGqY/go-cid"
cid
"gx/ipfs/QmXfiyr2RWEXpVDdaYnD2HNiBk6UBddsvEP4RPfXb6nGqY/go-cid"
mh
"gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash"
u
"gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
u
"gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
)
)
...
@@ -114,6 +115,9 @@ It reads from stdin, and <key> is a base58 encoded multihash.
...
@@ -114,6 +115,9 @@ It reads from stdin, and <key> is a base58 encoded multihash.
Arguments
:
[]
cmds
.
Argument
{
Arguments
:
[]
cmds
.
Argument
{
cmds
.
FileArg
(
"data"
,
true
,
false
,
"The data to be stored as an IPFS block."
)
.
EnableStdin
(),
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
)
{
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -139,7 +143,39 @@ It reads from stdin, and <key> is a base58 encoded multihash.
...
@@ -139,7 +143,39 @@ It reads from stdin, and <key> is a base58 encoded multihash.
return
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
())
log
.
Debugf
(
"BlockPut key: '%q'"
,
b
.
Cid
())
k
,
err
:=
n
.
Blocks
.
AddBlock
(
b
)
k
,
err
:=
n
.
Blocks
.
AddBlock
(
b
)
...
@@ -163,15 +199,15 @@ It reads from stdin, and <key> is a base58 encoded multihash.
...
@@ -163,15 +199,15 @@ It reads from stdin, and <key> is a base58 encoded multihash.
}
}
func
getBlockForKey
(
req
cmds
.
Request
,
skey
string
)
(
blocks
.
Block
,
error
)
{
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
()
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
!
u
.
IsValidHash
(
skey
)
{
return
nil
,
errors
.
New
(
"Not a valid hash"
)
}
c
,
err
:=
cid
.
Decode
(
skey
)
c
,
err
:=
cid
.
Decode
(
skey
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
test/sharness/t0050-block.sh
浏览文件 @
f68e1843
...
@@ -169,6 +169,21 @@ test_expect_success "multi-block 'ipfs block rm -q' produces no output" '
...
@@ -169,6 +169,21 @@ test_expect_success "multi-block 'ipfs block rm -q' produces no output" '
test ! -s block_rm_out
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
# Misc tests
#
#
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论