Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
db318333
提交
db318333
authored
12月 21, 2017
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi: dag review
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
f153c01d
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
23 行增加
和
21 行删除
+23
-21
dag.go
core/coreapi/dag.go
+5
-9
dag_test.go
core/coreapi/dag_test.go
+15
-10
interface.go
core/coreapi/interface/interface.go
+3
-2
没有找到文件。
core/coreapi/dag.go
浏览文件 @
db318333
...
...
@@ -19,7 +19,7 @@ type DagAPI struct {
*
caopts
.
DagOptions
}
func
(
api
*
DagAPI
)
Put
(
ctx
context
.
Context
,
src
io
.
Reader
,
opts
...
caopts
.
DagPutOption
)
(
[]
coreiface
.
Node
,
error
)
{
func
(
api
*
DagAPI
)
Put
(
ctx
context
.
Context
,
src
io
.
Reader
,
opts
...
caopts
.
DagPutOption
)
(
coreiface
.
Path
,
error
)
{
settings
,
err
:=
caopts
.
DagPutOptions
(
opts
...
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -38,16 +38,12 @@ func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPut
return
nil
,
fmt
.
Errorf
(
"no node returned from ParseInputs"
)
}
out
:=
make
([]
coreiface
.
Node
,
len
(
nds
))
for
n
,
nd
:=
range
nds
{
_
,
err
:=
api
.
node
.
DAG
.
Add
(
nd
)
if
err
!=
nil
{
return
nil
,
err
}
out
[
n
]
=
nd
_
,
err
=
api
.
node
.
DAG
.
Add
(
nds
[
0
])
if
err
!=
nil
{
return
nil
,
err
}
return
out
,
nil
return
ParseCid
(
nds
[
0
]
.
Cid
())
,
nil
}
func
(
api
*
DagAPI
)
Get
(
ctx
context
.
Context
,
path
coreiface
.
Path
)
(
coreiface
.
Node
,
error
)
{
...
...
core/coreapi/dag_test.go
浏览文件 @
db318333
...
...
@@ -33,8 +33,8 @@ func TestPut(t *testing.T) {
t
.
Error
(
err
)
}
if
res
[
0
]
.
Cid
()
.
String
()
!=
"zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv"
{
t
.
Errorf
(
"got wrong cid: %s"
,
res
[
0
]
.
Cid
()
.
String
())
if
res
.
Cid
()
.
String
()
!=
"zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv"
{
t
.
Errorf
(
"got wrong cid: %s"
,
res
.
Cid
()
.
String
())
}
}
...
...
@@ -50,8 +50,8 @@ func TestPutWithHash(t *testing.T) {
t
.
Error
(
err
)
}
if
res
[
0
]
.
Cid
()
.
String
()
!=
"z5hRLNd2sv4z1c"
{
t
.
Errorf
(
"got wrong cid: %s"
,
res
[
0
]
.
Cid
()
.
String
())
if
res
.
Cid
()
.
String
()
!=
"z5hRLNd2sv4z1c"
{
t
.
Errorf
(
"got wrong cid: %s"
,
res
.
Cid
()
.
String
())
}
}
...
...
@@ -67,12 +67,12 @@ func TestPath(t *testing.T) {
t
.
Error
(
err
)
}
res
,
err
:=
api
.
Dag
()
.
Put
(
ctx
,
strings
.
NewReader
(
`{"lnk": {"/": "`
+
sub
[
0
]
.
Cid
()
.
String
()
+
`"}}`
))
res
,
err
:=
api
.
Dag
()
.
Put
(
ctx
,
strings
.
NewReader
(
`{"lnk": {"/": "`
+
sub
.
Cid
()
.
String
()
+
`"}}`
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
p
,
err
:=
coreapi
.
ParsePath
(
path
.
Join
(
res
[
0
]
.
Cid
()
.
String
(),
"lnk"
))
p
,
err
:=
coreapi
.
ParsePath
(
path
.
Join
(
res
.
Cid
()
.
String
(),
"lnk"
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -82,8 +82,8 @@ func TestPath(t *testing.T) {
t
.
Error
(
err
)
}
if
nd
.
Cid
()
.
String
()
!=
sub
[
0
]
.
Cid
()
.
String
()
{
t
.
Errorf
(
"got unexpected cid %s, expected %s"
,
nd
.
Cid
()
.
String
(),
sub
[
0
]
.
Cid
()
.
String
())
if
nd
.
Cid
()
.
String
()
!=
sub
.
Cid
()
.
String
()
{
t
.
Errorf
(
"got unexpected cid %s, expected %s"
,
nd
.
Cid
()
.
String
(),
sub
.
Cid
()
.
String
())
}
}
...
...
@@ -94,12 +94,17 @@ func TestTree(t *testing.T) {
t
.
Error
(
err
)
}
res
,
err
:=
api
.
Dag
()
.
Put
(
ctx
,
strings
.
NewReader
(
`{"a": 123, "b": "foo", "c": {"d": 321, "e": 111}}`
))
c
,
err
:=
api
.
Dag
()
.
Put
(
ctx
,
strings
.
NewReader
(
`{"a": 123, "b": "foo", "c": {"d": 321, "e": 111}}`
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
lst
:=
res
[
0
]
.
Tree
(
""
,
-
1
)
res
,
err
:=
api
.
Dag
()
.
Get
(
ctx
,
c
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
lst
:=
res
.
Tree
(
""
,
-
1
)
if
len
(
lst
)
!=
len
(
treeExpected
)
{
t
.
Errorf
(
"tree length of %d doesn't match expected %d"
,
len
(
lst
),
len
(
treeExpected
))
}
...
...
core/coreapi/interface/interface.go
浏览文件 @
db318333
...
...
@@ -61,8 +61,9 @@ type UnixfsAPI interface {
// DagAPI specifies the interface to IPLD
type
DagAPI
interface
{
// Put inserts data using specified format and input encoding.
// If format is not specified (nil), default dag-cbor/sha256 is used
Put
(
ctx
context
.
Context
,
src
io
.
Reader
,
opts
...
options
.
DagPutOption
)
([]
Node
,
error
)
// Unless used with WithCodec or WithHash, the defaults "dag-cbor" and
// "sha256" are used.
Put
(
ctx
context
.
Context
,
src
io
.
Reader
,
opts
...
options
.
DagPutOption
)
(
Path
,
error
)
// WithInputEnc is an option for Put which specifies the input encoding of the
// data. Default is "json", most formats/codecs support "raw"
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论