Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
6337e69f
提交
6337e69f
authored
9月 20, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi unixfs: layout/chunker options
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
041e55d7
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
51 行增加
和
3 行删除
+51
-3
unixfs.go
core/coreapi/interface/options/unixfs.go
+27
-0
unixfs.go
core/coreapi/unixfs.go
+10
-2
unixfs_test.go
core/coreapi/unixfs_test.go
+14
-1
没有找到文件。
core/coreapi/interface/options/unixfs.go
浏览文件 @
6337e69f
...
...
@@ -4,6 +4,13 @@ import (
mh
"gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
)
type
Layout
int
const
(
BalancedLayout
Layout
=
iota
TrickleLeyout
)
type
UnixfsAddSettings
struct
{
CidVersion
int
MhType
uint64
...
...
@@ -11,6 +18,9 @@ type UnixfsAddSettings struct {
InlineLimit
int
RawLeaves
bool
RawLeavesSet
bool
Chunker
string
Layout
Layout
}
type
UnixfsAddOption
func
(
*
UnixfsAddSettings
)
error
...
...
@@ -23,6 +33,9 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, error) {
InlineLimit
:
0
,
RawLeaves
:
false
,
RawLeavesSet
:
false
,
Chunker
:
"size-262144"
,
Layout
:
BalancedLayout
,
}
for
_
,
opt
:=
range
opts
{
...
...
@@ -67,3 +80,17 @@ func (unixfsOpts) InlineLimit(limit int) UnixfsAddOption {
return
nil
}
}
func
(
unixfsOpts
)
Chunker
(
chunker
string
)
UnixfsAddOption
{
return
func
(
settings
*
UnixfsAddSettings
)
error
{
settings
.
Chunker
=
chunker
return
nil
}
}
func
(
unixfsOpts
)
Layout
(
layout
Layout
)
UnixfsAddOption
{
return
func
(
settings
*
UnixfsAddSettings
)
error
{
settings
.
Layout
=
layout
return
nil
}
}
core/coreapi/unixfs.go
浏览文件 @
6337e69f
...
...
@@ -68,10 +68,9 @@ func (api *UnixfsAPI) Add(ctx context.Context, r io.ReadCloser, opts ...options.
}
fileAdder
.
Out
=
outChan
//fileAdder.Chunker = c
hunker
fileAdder
.
Chunker
=
settings
.
C
hunker
//fileAdder.Progress = progress
//fileAdder.Hidden = hidden
//fileAdder.Trickle = trickle
//fileAdder.Wrap = wrap
//fileAdder.Pin = dopin
fileAdder
.
Silent
=
false
...
...
@@ -80,6 +79,15 @@ func (api *UnixfsAPI) Add(ctx context.Context, r io.ReadCloser, opts ...options.
//fileAdder.Name = pathName
fileAdder
.
CidBuilder
=
prefix
switch
settings
.
Layout
{
case
options
.
BalancedLayout
:
// Default
case
options
.
TrickleLeyout
:
fileAdder
.
Trickle
=
true
default
:
return
nil
,
fmt
.
Errorf
(
"unknown layout: %d"
,
settings
.
Layout
)
}
if
settings
.
InlineLimit
>
0
{
fileAdder
.
CidBuilder
=
cidutil
.
InlineBuilder
{
Builder
:
fileAdder
.
CidBuilder
,
...
...
core/coreapi/unixfs_test.go
浏览文件 @
6337e69f
...
...
@@ -191,6 +191,19 @@ func TestAdd(t *testing.T) {
path
:
"/ipfs/zj7Gr8AcBreqGEfrnR5kPFe"
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
InlineLimit
(
32
),
options
.
Unixfs
.
RawLeaves
(
true
)},
},
// Chunker / Layout
{
name
:
"addChunks"
,
data
:
strings
.
Repeat
(
"aoeuidhtns"
,
200
),
path
:
"/ipfs/QmRo11d4QJrST47aaiGVJYwPhoNA4ihRpJ5WaxBWjWDwbX"
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Chunker
(
"size-4"
)},
},
{
name
:
"addChunksTrickle"
,
data
:
strings
.
Repeat
(
"aoeuidhtns"
,
200
),
path
:
"/ipfs/QmNNhDGttafX3M1wKWixGre6PrLFGjnoPEDXjBYpTv93HP"
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Chunker
(
"size-4"
),
options
.
Unixfs
.
Layout
(
options
.
TrickleLeyout
)},
},
}
for
_
,
testCase
:=
range
cases
{
...
...
@@ -211,7 +224,7 @@ func TestAdd(t *testing.T) {
}
if
p
.
String
()
!=
testCase
.
path
{
t
.
Fatalf
(
"expected path %s, got: %s"
,
hello
,
p
)
t
.
Errorf
(
"expected path %s, got: %s"
,
testCase
.
path
,
p
)
}
r
,
err
:=
api
.
Unixfs
()
.
Cat
(
ctx
,
p
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论