Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
18fec6eb
提交
18fec6eb
authored
10月 03, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi unixfs: wrap option
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
c6f8e7e2
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
76 行增加
和
16 行删除
+76
-16
unixfs.go
core/coreapi/interface/options/unixfs.go
+13
-0
unixfs.go
core/coreapi/unixfs.go
+1
-1
unixfs_test.go
core/coreapi/unixfs_test.go
+62
-15
没有找到文件。
core/coreapi/interface/options/unixfs.go
浏览文件 @
18fec6eb
...
...
@@ -31,6 +31,8 @@ type UnixfsAddSettings struct {
Pin
bool
OnlyHash
bool
Local
bool
Wrap
bool
}
type
UnixfsAddOption
func
(
*
UnixfsAddSettings
)
error
...
...
@@ -51,6 +53,8 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
Pin
:
false
,
OnlyHash
:
false
,
Local
:
false
,
Wrap
:
false
,
}
for
_
,
opt
:=
range
opts
{
...
...
@@ -202,3 +206,12 @@ func (unixfsOpts) Local(local bool) UnixfsAddOption {
return
nil
}
}
// Wrap tells the adder to wrap the added file structure with an additional
// directory.
func
(
unixfsOpts
)
Wrap
(
wrap
bool
)
UnixfsAddOption
{
return
func
(
settings
*
UnixfsAddSettings
)
error
{
settings
.
Wrap
=
wrap
return
nil
}
}
core/coreapi/unixfs.go
浏览文件 @
18fec6eb
...
...
@@ -66,7 +66,7 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.File, opts ...options
fileAdder
.
Chunker
=
settings
.
Chunker
//fileAdder.Progress = progress
//fileAdder.Hidden = hidden
//fileAdder.Wrap = w
rap
fileAdder
.
Wrap
=
settings
.
W
rap
fileAdder
.
Pin
=
settings
.
Pin
&&
!
settings
.
OnlyHash
fileAdder
.
Silent
=
true
fileAdder
.
RawLeaves
=
settings
.
RawLeaves
...
...
core/coreapi/unixfs_test.go
浏览文件 @
18fec6eb
...
...
@@ -134,6 +134,18 @@ func strFile(data string) func() files.File {
}
}
func
twoLevelDir
()
func
()
files
.
File
{
return
func
()
files
.
File
{
return
files
.
NewSliceFile
(
"t"
,
"t"
,
[]
files
.
File
{
files
.
NewSliceFile
(
"t/abc"
,
"t/abc"
,
[]
files
.
File
{
files
.
NewReaderFile
(
"t/abc/def"
,
"t/abc/def"
,
ioutil
.
NopCloser
(
strings
.
NewReader
(
"world"
)),
nil
),
}),
files
.
NewReaderFile
(
"t/bar"
,
"t/bar"
,
ioutil
.
NopCloser
(
strings
.
NewReader
(
"hello2"
)),
nil
),
files
.
NewReaderFile
(
"t/foo"
,
"t/foo"
,
ioutil
.
NopCloser
(
strings
.
NewReader
(
"hello1"
)),
nil
),
})
}
}
func
TestAdd
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
_
,
api
,
err
:=
makeAPI
(
ctx
)
...
...
@@ -142,12 +154,16 @@ func TestAdd(t *testing.T) {
}
cases
:=
[]
struct
{
name
string
data
func
()
files
.
File
path
string
err
string
name
string
data
func
()
files
.
File
path
string
err
string
recursive
bool
opts
[]
options
.
UnixfsAddOption
wrapped
bool
opts
[]
options
.
UnixfsAddOption
}{
// Simple cases
{
...
...
@@ -232,6 +248,12 @@ func TestAdd(t *testing.T) {
path
:
hello
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Local
(
true
)},
},
{
name
:
"hashOnly"
,
// test (non)fetchability
data
:
strFile
(
helloStr
),
path
:
hello
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
HashOnly
(
true
)},
},
// multi file
{
name
:
"simpleDir"
,
...
...
@@ -245,18 +267,36 @@ func TestAdd(t *testing.T) {
path
:
"/ipfs/QmRKGpFfR32FVXdvJiHfo4WJ5TDYBsM1P9raAp1p6APWSp"
,
},
{
name
:
"twoLevelDir"
,
name
:
"twoLevelDir"
,
data
:
twoLevelDir
(),
recursive
:
true
,
path
:
"/ipfs/QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
,
},
// wrapped
{
name
:
"addWrapped"
,
path
:
"/ipfs/QmVE9rNpj5doj7XHzp5zMUxD7BJgXEqx4pe3xZ3JBReWHE"
,
data
:
func
()
files
.
File
{
return
files
.
NewSliceFile
(
"t"
,
"t"
,
[]
files
.
File
{
files
.
NewSliceFile
(
"t/abc"
,
"t/abc"
,
[]
files
.
File
{
files
.
NewReaderFile
(
"t/abc/def"
,
"t/abc/def"
,
ioutil
.
NopCloser
(
strings
.
NewReader
(
"world"
)),
nil
),
}),
files
.
NewReaderFile
(
"t/bar"
,
"t/bar"
,
ioutil
.
NopCloser
(
strings
.
NewReader
(
"hello2"
)),
nil
),
files
.
NewReaderFile
(
"t/foo"
,
"t/foo"
,
ioutil
.
NopCloser
(
strings
.
NewReader
(
"hello1"
)),
nil
),
})
return
files
.
NewReaderFile
(
"foo"
,
"foo"
,
ioutil
.
NopCloser
(
strings
.
NewReader
(
helloStr
)),
nil
)
},
wrapped
:
true
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Wrap
(
true
)},
},
{
name
:
"twoLevelDirWrapped"
,
data
:
twoLevelDir
(),
recursive
:
true
,
path
:
"/ipfs/QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
,
wrapped
:
true
,
path
:
"/ipfs/QmPwsL3T5sWhDmmAWZHAzyjKtMVDS9a11aHNRqb3xoVnmg"
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Wrap
(
true
)},
},
{
name
:
"twoLevelInlineHash"
,
data
:
twoLevelDir
(),
recursive
:
true
,
wrapped
:
true
,
path
:
"/ipfs/zBunoruKoyCHKkALNSWxDvj4L7yuQnMgQ4hUa9j1Z64tVcDEcu6Zdetyu7eeFCxMPfxb7YJvHeFHoFoHMkBUQf6vfdhmi"
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Wrap
(
true
),
options
.
Unixfs
.
Inline
(
true
),
options
.
Unixfs
.
RawLeaves
(
true
),
options
.
Unixfs
.
Hash
(
mh
.
SHA3
)},
},
}
...
...
@@ -338,7 +378,14 @@ func TestAdd(t *testing.T) {
t
.
Fatal
(
err
)
}
cmpFile
(
testCase
.
data
(),
f
)
orig
:=
testCase
.
data
()
if
testCase
.
wrapped
{
orig
=
files
.
NewSliceFile
(
""
,
""
,
[]
files
.
File
{
orig
,
})
}
cmpFile
(
orig
,
f
)
})
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论