Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
8bb45fda
Commit
8bb45fda
authored
Feb 06, 2018
by
Hector Sanjuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Golint: make BufDagReader public
License: MIT Signed-off-by:
Hector Sanjuan
<
hector@protocol.ai
>
parent
ca4271b7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
13 deletions
+19
-13
unixfs/io/bufdagreader.go
unixfs/io/bufdagreader.go
+15
-9
unixfs/io/dagreader.go
unixfs/io/dagreader.go
+1
-1
unixfs/io/pbdagreader.go
unixfs/io/pbdagreader.go
+3
-3
No files found.
unixfs/io/bufdagreader.go
View file @
8bb45fda
...
...
@@ -6,27 +6,32 @@ import (
"io"
)
type
bufDagReader
struct
{
// BufDagReader implements a DagReader that reads from a byte slice
// using a bytes.Reader. It is used for RawNodes.
type
BufDagReader
struct
{
*
bytes
.
Reader
}
//
n
ewBufDagReader returns a DAG reader for the given byte slice.
//
N
ewBufDagReader returns a DAG reader for the given byte slice.
// BufDagReader is used to read RawNodes.
func
n
ewBufDagReader
(
b
[]
byte
)
*
b
ufDagReader
{
return
&
b
ufDagReader
{
bytes
.
NewReader
(
b
)}
func
N
ewBufDagReader
(
b
[]
byte
)
*
B
ufDagReader
{
return
&
B
ufDagReader
{
bytes
.
NewReader
(
b
)}
}
var
_
DagReader
=
(
*
b
ufDagReader
)(
nil
)
var
_
DagReader
=
(
*
B
ufDagReader
)(
nil
)
func
(
*
bufDagReader
)
Close
()
error
{
// Close is a nop.
func
(
*
BufDagReader
)
Close
()
error
{
return
nil
}
func
(
rd
*
bufDagReader
)
CtxReadFull
(
ctx
context
.
Context
,
b
[]
byte
)
(
int
,
error
)
{
// CtxReadFull reads the slice onto b.
func
(
rd
*
BufDagReader
)
CtxReadFull
(
ctx
context
.
Context
,
b
[]
byte
)
(
int
,
error
)
{
return
rd
.
Read
(
b
)
}
func
(
rd
*
bufDagReader
)
Offset
()
int64
{
// Offset returns the current offset.
func
(
rd
*
BufDagReader
)
Offset
()
int64
{
of
,
err
:=
rd
.
Seek
(
0
,
io
.
SeekCurrent
)
if
err
!=
nil
{
panic
(
"this should never happen "
+
err
.
Error
())
...
...
@@ -34,7 +39,8 @@ func (rd *bufDagReader) Offset() int64 {
return
of
}
func
(
rd
*
bufDagReader
)
Size
()
uint64
{
// Size returns the size of the buffer.
func
(
rd
*
BufDagReader
)
Size
()
uint64
{
s
:=
rd
.
Reader
.
Size
()
if
s
<
0
{
panic
(
"size smaller than 0 (impossible!!)"
)
...
...
unixfs/io/dagreader.go
View file @
8bb45fda
...
...
@@ -43,7 +43,7 @@ type ReadSeekCloser interface {
func
NewDagReader
(
ctx
context
.
Context
,
n
ipld
.
Node
,
serv
ipld
.
NodeGetter
)
(
DagReader
,
error
)
{
switch
n
:=
n
.
(
type
)
{
case
*
mdag
.
RawNode
:
return
n
ewBufDagReader
(
n
.
RawData
()),
nil
return
N
ewBufDagReader
(
n
.
RawData
()),
nil
case
*
mdag
.
ProtoNode
:
pb
:=
new
(
ftpb
.
Data
)
if
err
:=
proto
.
Unmarshal
(
n
.
Data
(),
pb
);
err
!=
nil
{
...
...
unixfs/io/pbdagreader.go
View file @
8bb45fda
...
...
@@ -57,7 +57,7 @@ func NewPBFileReader(ctx context.Context, n *mdag.ProtoNode, pb *ftpb.Data, serv
return
&
PBDagReader
{
node
:
n
,
serv
:
serv
,
buf
:
n
ewBufDagReader
(
pb
.
GetData
()),
buf
:
N
ewBufDagReader
(
pb
.
GetData
()),
promises
:
make
([]
*
ipld
.
NodePromise
,
len
(
curLinks
)),
links
:
curLinks
,
ctx
:
fctx
,
...
...
@@ -119,7 +119,7 @@ func (dr *PBDagReader) precalcNextBuf(ctx context.Context) error {
dr
.
buf
=
NewPBFileReader
(
dr
.
ctx
,
nxt
,
pb
,
dr
.
serv
)
return
nil
case
ftpb
.
Data_Raw
:
dr
.
buf
=
n
ewBufDagReader
(
pb
.
GetData
())
dr
.
buf
=
N
ewBufDagReader
(
pb
.
GetData
())
return
nil
case
ftpb
.
Data_Metadata
:
return
errors
.
New
(
"shouldnt have had metadata object inside file"
)
...
...
@@ -256,7 +256,7 @@ func (dr *PBDagReader) Seek(offset int64, whence int) (int64, error) {
if
dr
.
buf
!=
nil
{
dr
.
buf
.
Close
()
}
dr
.
buf
=
n
ewBufDagReader
(
pb
.
GetData
()[
offset
:
])
dr
.
buf
=
N
ewBufDagReader
(
pb
.
GetData
()[
offset
:
])
// start reading links from the beginning
dr
.
linkPosition
=
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment