Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
72451510
Unverified
提交
72451510
authored
11月 21, 2016
作者:
Jakub Sztandera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make unixio.DagReader an interface
License: MIT Signed-off-by:
Jakub Sztandera
<
kubuxu@protonmail.ch
>
上级
bf9927fb
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
24 行增加
和
17 行删除
+24
-17
cat.go
core/coreunix/cat.go
+1
-1
dagreader.go
unixfs/io/dagreader.go
+21
-14
dagreader_test.go
unixfs/io/dagreader_test.go
+1
-1
dagmodifier.go
unixfs/mod/dagmodifier.go
+1
-1
没有找到文件。
core/coreunix/cat.go
浏览文件 @
72451510
...
...
@@ -8,7 +8,7 @@ import (
uio
"github.com/ipfs/go-ipfs/unixfs/io"
)
func
Cat
(
ctx
context
.
Context
,
n
*
core
.
IpfsNode
,
pstr
string
)
(
*
uio
.
DagReader
,
error
)
{
func
Cat
(
ctx
context
.
Context
,
n
*
core
.
IpfsNode
,
pstr
string
)
(
uio
.
DagReader
,
error
)
{
dagNode
,
err
:=
core
.
Resolve
(
ctx
,
n
.
Namesys
,
n
.
Resolver
,
path
.
Path
(
pstr
))
if
err
!=
nil
{
return
nil
,
err
...
...
unixfs/io/dagreader.go
浏览文件 @
72451510
...
...
@@ -20,8 +20,15 @@ var ErrIsDir = errors.New("this dag node is a directory")
var
ErrCantReadSymlinks
=
errors
.
New
(
"cannot currently read symlinks"
)
type
DagReader
interface
{
ReadSeekCloser
Size
()
uint64
CtxReadFull
(
context
.
Context
,
[]
byte
)
(
int
,
error
)
Offset
()
int64
}
// DagReader provides a way to easily read the data contained in a dag.
type
DagReader
struct
{
type
pb
DagReader
struct
{
serv
mdag
.
DAGService
// the node being read
...
...
@@ -59,10 +66,10 @@ type ReadSeekCloser interface {
// NewDagReader creates a new reader object that reads the data represented by
// the given node, using the passed in DAGService for data retreival
func
NewDagReader
(
ctx
context
.
Context
,
n
node
.
Node
,
serv
mdag
.
DAGService
)
(
*
DagReader
,
error
)
{
func
NewDagReader
(
ctx
context
.
Context
,
n
node
.
Node
,
serv
mdag
.
DAGService
)
(
DagReader
,
error
)
{
switch
n
:=
n
.
(
type
)
{
case
*
mdag
.
RawNode
:
return
&
DagReader
{
return
&
pb
DagReader
{
buf
:
NewRSNCFromBytes
(
n
.
RawData
()),
},
nil
case
*
mdag
.
ProtoNode
:
...
...
@@ -101,10 +108,10 @@ func NewDagReader(ctx context.Context, n node.Node, serv mdag.DAGService) (*DagR
}
}
func
NewDataFileReader
(
ctx
context
.
Context
,
n
*
mdag
.
ProtoNode
,
pb
*
ftpb
.
Data
,
serv
mdag
.
DAGService
)
*
DagReader
{
func
NewDataFileReader
(
ctx
context
.
Context
,
n
*
mdag
.
ProtoNode
,
pb
*
ftpb
.
Data
,
serv
mdag
.
DAGService
)
*
pb
DagReader
{
fctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
promises
:=
mdag
.
GetDAG
(
fctx
,
serv
,
n
)
return
&
DagReader
{
return
&
pb
DagReader
{
node
:
n
,
serv
:
serv
,
buf
:
NewRSNCFromBytes
(
pb
.
GetData
()),
...
...
@@ -117,7 +124,7 @@ func NewDataFileReader(ctx context.Context, n *mdag.ProtoNode, pb *ftpb.Data, se
// precalcNextBuf follows the next link in line and loads it from the
// DAGService, setting the next buffer to read from
func
(
dr
*
DagReader
)
precalcNextBuf
(
ctx
context
.
Context
)
error
{
func
(
dr
*
pb
DagReader
)
precalcNextBuf
(
ctx
context
.
Context
)
error
{
dr
.
buf
.
Close
()
// Just to make sure
if
dr
.
linkPosition
>=
len
(
dr
.
promises
)
{
return
io
.
EOF
...
...
@@ -158,22 +165,22 @@ func (dr *DagReader) precalcNextBuf(ctx context.Context) error {
dr
.
buf
=
NewRSNCFromBytes
(
nxt
.
RawData
())
return
nil
default
:
return
errors
.
New
(
"unrecognized node type in DagReader"
)
return
errors
.
New
(
"unrecognized node type in
pb
DagReader"
)
}
}
// Size return the total length of the data from the DAG structured file.
func
(
dr
*
DagReader
)
Size
()
uint64
{
func
(
dr
*
pb
DagReader
)
Size
()
uint64
{
return
dr
.
pbdata
.
GetFilesize
()
}
// Read reads data from the DAG structured file
func
(
dr
*
DagReader
)
Read
(
b
[]
byte
)
(
int
,
error
)
{
func
(
dr
*
pb
DagReader
)
Read
(
b
[]
byte
)
(
int
,
error
)
{
return
dr
.
CtxReadFull
(
dr
.
ctx
,
b
)
}
// CtxReadFull reads data from the DAG structured file
func
(
dr
*
DagReader
)
CtxReadFull
(
ctx
context
.
Context
,
b
[]
byte
)
(
int
,
error
)
{
func
(
dr
*
pb
DagReader
)
CtxReadFull
(
ctx
context
.
Context
,
b
[]
byte
)
(
int
,
error
)
{
// If no cached buffer, load one
total
:=
0
for
{
...
...
@@ -201,7 +208,7 @@ func (dr *DagReader) CtxReadFull(ctx context.Context, b []byte) (int, error) {
}
}
func
(
dr
*
DagReader
)
WriteTo
(
w
io
.
Writer
)
(
int64
,
error
)
{
func
(
dr
*
pb
DagReader
)
WriteTo
(
w
io
.
Writer
)
(
int64
,
error
)
{
// If no cached buffer, load one
total
:=
int64
(
0
)
for
{
...
...
@@ -226,12 +233,12 @@ func (dr *DagReader) WriteTo(w io.Writer) (int64, error) {
}
}
func
(
dr
*
DagReader
)
Close
()
error
{
func
(
dr
*
pb
DagReader
)
Close
()
error
{
dr
.
cancel
()
return
nil
}
func
(
dr
*
DagReader
)
Offset
()
int64
{
func
(
dr
*
pb
DagReader
)
Offset
()
int64
{
return
dr
.
offset
}
...
...
@@ -239,7 +246,7 @@ func (dr *DagReader) Offset() int64 {
// interface matches standard unix seek
// TODO: check if we can do relative seeks, to reduce the amount of dagreader
// recreations that need to happen.
func
(
dr
*
DagReader
)
Seek
(
offset
int64
,
whence
int
)
(
int64
,
error
)
{
func
(
dr
*
pb
DagReader
)
Seek
(
offset
int64
,
whence
int
)
(
int64
,
error
)
{
switch
whence
{
case
os
.
SEEK_SET
:
if
offset
<
0
{
...
...
unixfs/io/dagreader_test.go
浏览文件 @
72451510
...
...
@@ -236,7 +236,7 @@ func TestReaderSzie(t *testing.T) {
}
}
func
readByte
(
t
testing
.
TB
,
reader
*
DagReader
)
byte
{
func
readByte
(
t
testing
.
TB
,
reader
DagReader
)
byte
{
out
:=
make
([]
byte
,
1
)
c
,
err
:=
reader
.
Read
(
out
)
...
...
unixfs/mod/dagmodifier.go
浏览文件 @
72451510
...
...
@@ -43,7 +43,7 @@ type DagModifier struct {
curWrOff
uint64
wrBuf
*
bytes
.
Buffer
read
*
uio
.
DagReader
read
uio
.
DagReader
}
func
NewDagModifier
(
ctx
context
.
Context
,
from
node
.
Node
,
serv
mdag
.
DAGService
,
spl
chunk
.
SplitterGen
)
(
*
DagModifier
,
error
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论