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-unixfs
Commits
9f1f2cdb
Commit
9f1f2cdb
authored
Jul 18, 2018
by
Whyrusleeping
Committed by
GitHub
Jul 18, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5237 from schomatis/fix/unixfs/dag-reader/next-buf
unixfs: refactor `precalcNextBuf`
parents
999c6686
0271059b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
17 deletions
+14
-17
io/dagreader.go
io/dagreader.go
+2
-2
io/pbdagreader.go
io/pbdagreader.go
+12
-14
unixfs.go
unixfs.go
+0
-1
No files found.
io/dagreader.go
View file @
9f1f2cdb
...
...
@@ -3,7 +3,6 @@ package io
import
(
"context"
"errors"
"fmt"
"io"
mdag
"github.com/ipfs/go-ipfs/merkledag"
...
...
@@ -17,6 +16,7 @@ import (
var
(
ErrIsDir
=
errors
.
New
(
"this dag node is a directory"
)
ErrCantReadSymlinks
=
errors
.
New
(
"cannot currently read symlinks"
)
ErrUnkownNodeType
=
errors
.
New
(
"unknown node type"
)
)
// A DagReader provides read-only read and seek acess to a unixfs file.
...
...
@@ -74,6 +74,6 @@ func NewDagReader(ctx context.Context, n ipld.Node, serv ipld.NodeGetter) (DagRe
return
nil
,
ft
.
ErrUnrecognizedType
}
default
:
return
nil
,
fmt
.
Errorf
(
"unrecognized n
ode
t
ype
"
)
return
nil
,
ErrUnkownN
ode
T
ype
}
}
io/pbdagreader.go
View file @
9f1f2cdb
...
...
@@ -122,34 +122,32 @@ func (dr *PBDagReader) precalcNextBuf(ctx context.Context) error {
dr
.
linkPosition
++
switch
nxt
:=
nxt
.
(
type
)
{
return
dr
.
loadBufNode
(
nxt
)
}
func
(
dr
*
PBDagReader
)
loadBufNode
(
node
ipld
.
Node
)
error
{
switch
node
:=
node
.
(
type
)
{
case
*
mdag
.
ProtoNode
:
fsNode
,
err
:=
ft
.
FSNodeFromBytes
(
n
xt
.
Data
())
fsNode
,
err
:=
ft
.
FSNodeFromBytes
(
n
ode
.
Data
())
if
err
!=
nil
{
return
fmt
.
Errorf
(
"incorrectly formatted protobuf: %s"
,
err
)
}
switch
fsNode
.
Type
()
{
case
ftpb
.
Data_Directory
,
ftpb
.
Data_HAMTShard
:
// A directory should not exist within a file
return
ft
.
ErrInvalidDirLocation
case
ftpb
.
Data_File
:
dr
.
buf
=
NewPBFileReader
(
dr
.
ctx
,
n
xt
,
fsNode
,
dr
.
serv
)
dr
.
buf
=
NewPBFileReader
(
dr
.
ctx
,
n
ode
,
fsNode
,
dr
.
serv
)
return
nil
case
ftpb
.
Data_Raw
:
dr
.
buf
=
NewBufDagReader
(
fsNode
.
Data
())
return
nil
case
ftpb
.
Data_Metadata
:
return
errors
.
New
(
"shouldnt have had metadata object inside file"
)
case
ftpb
.
Data_Symlink
:
return
errors
.
New
(
"shouldnt have had symlink inside file"
)
default
:
return
ft
.
Err
UnrecognizedType
return
f
m
t
.
Err
orf
(
"found %s node in unexpected place"
,
fsNode
.
Type
()
.
String
())
}
case
*
mdag
.
RawNode
:
dr
.
buf
=
NewBufDagReader
(
node
.
RawData
())
return
nil
default
:
var
err
error
dr
.
buf
,
err
=
NewDagReader
(
ctx
,
nxt
,
dr
.
serv
)
return
err
return
ErrUnkownNodeType
}
}
...
...
unixfs.go
View file @
9f1f2cdb
...
...
@@ -25,7 +25,6 @@ const (
// Common errors
var
(
ErrMalformedFileFormat
=
errors
.
New
(
"malformed data in file format"
)
ErrInvalidDirLocation
=
errors
.
New
(
"found directory node in unexpected place"
)
ErrUnrecognizedType
=
errors
.
New
(
"unrecognized node type"
)
)
...
...
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