Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
c68ab562
提交
c68ab562
authored
9月 20, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi unixfs: cid prefix options
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
795d1ea5
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
56 行增加
和
5 行删除
+56
-5
unixfs.go
core/coreapi/interface/options/unixfs.go
+6
-2
unixfs.go
core/coreapi/interface/unixfs.go
+1
-0
unixfs.go
core/coreapi/unixfs.go
+49
-3
没有找到文件。
core/coreapi/interface/options/unixfs.go
浏览文件 @
c68ab562
...
...
@@ -8,7 +8,9 @@ type UnixfsAddSettings struct {
CidVersion
int
MhType
uint64
InlineLimit
int
InlineLimit
int
RawLeaves
bool
RawLeavesSet
bool
}
type
UnixfsAddOption
func
(
*
UnixfsAddSettings
)
error
...
...
@@ -18,7 +20,9 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, error) {
CidVersion
:
-
1
,
MhType
:
mh
.
SHA2_256
,
InlineLimit
:
0
,
InlineLimit
:
0
,
RawLeaves
:
false
,
RawLeavesSet
:
false
,
}
for
_
,
opt
:=
range
opts
{
...
...
core/coreapi/interface/unixfs.go
浏览文件 @
c68ab562
...
...
@@ -10,6 +10,7 @@ import (
)
// UnixfsAPI is the basic interface to immutable files in IPFS
// NOTE: This API is heavily WIP, things are guaranteed to break frequently
type
UnixfsAPI
interface
{
// Add imports the data from the reader into merkledag file
Add
(
context
.
Context
,
io
.
ReadCloser
,
...
options
.
UnixfsAddOption
)
(
ResolvedPath
,
error
)
...
...
core/coreapi/unixfs.go
浏览文件 @
c68ab562
...
...
@@ -2,15 +2,19 @@ package coreapi
import
(
"context"
"errors"
"fmt"
"io"
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
options
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
coreunix
"github.com/ipfs/go-ipfs/core/coreunix"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
"github.com/ipfs/go-ipfs/core/coreunix"
cid
"gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
mh
"gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
files
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit/files"
uio
"gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
dag
"gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
ipld
"gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
)
...
...
@@ -19,11 +23,42 @@ type UnixfsAPI CoreAPI
// Add builds a merkledag node from a reader, adds it to the blockstore,
// and returns the key representing that node.
func
(
api
*
UnixfsAPI
)
Add
(
ctx
context
.
Context
,
r
io
.
ReadCloser
,
opts
...
options
.
UnixfsAddOption
)
(
coreiface
.
ResolvedPath
,
error
)
{
_
,
err
:=
options
.
UnixfsAddOptions
(
opts
...
)
settings
,
err
:=
options
.
UnixfsAddOptions
(
opts
...
)
if
err
!=
nil
{
return
nil
,
err
}
// TODO: move to options
// (hash != "sha2-256") -> CIDv1
if
settings
.
MhType
!=
mh
.
SHA2_256
{
switch
settings
.
CidVersion
{
case
0
:
return
nil
,
errors
.
New
(
"CIDv0 only supports sha2-256"
)
case
1
,
-
1
:
settings
.
CidVersion
=
1
default
:
return
nil
,
fmt
.
Errorf
(
"unknown CID version: %d"
,
settings
.
CidVersion
)
}
}
else
{
if
settings
.
CidVersion
<
0
{
// Default to CIDv0
settings
.
CidVersion
=
0
}
}
// cidV1 -> raw blocks (by default)
if
settings
.
CidVersion
>
0
&&
!
settings
.
RawLeavesSet
{
settings
.
RawLeaves
=
true
}
prefix
,
err
:=
dag
.
PrefixForCidVersion
(
settings
.
CidVersion
)
if
err
!=
nil
{
return
nil
,
err
}
prefix
.
MhType
=
settings
.
MhType
prefix
.
MhLength
=
-
1
outChan
:=
make
(
chan
interface
{},
1
)
fileAdder
,
err
:=
coreunix
.
NewAdder
(
ctx
,
api
.
node
.
Pinning
,
api
.
node
.
Blockstore
,
api
.
node
.
DAG
)
...
...
@@ -32,6 +67,17 @@ func (api *UnixfsAPI) Add(ctx context.Context, r io.ReadCloser, opts ...options.
}
fileAdder
.
Out
=
outChan
//fileAdder.Chunker = chunker
//fileAdder.Progress = progress
//fileAdder.Hidden = hidden
//fileAdder.Trickle = trickle
//fileAdder.Wrap = wrap
//fileAdder.Pin = dopin
fileAdder
.
Silent
=
false
fileAdder
.
RawLeaves
=
settings
.
RawLeaves
//fileAdder.NoCopy = nocopy
//fileAdder.Name = pathName
fileAdder
.
CidBuilder
=
prefix
err
=
fileAdder
.
AddFile
(
files
.
NewReaderFile
(
""
,
""
,
r
,
nil
))
if
err
!=
nil
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论