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
64720f3b
Commit
64720f3b
authored
Oct 18, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
raw dag: make raw nodes work in cat and get, add tests
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
f47e36a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
24 deletions
+27
-24
io/dagreader.go
io/dagreader.go
+27
-24
No files found.
io/dagreader.go
View file @
64720f3b
...
...
@@ -129,33 +129,36 @@ func (dr *DagReader) precalcNextBuf(ctx context.Context) error {
}
dr
.
linkPosition
++
nxtpb
,
ok
:=
nxt
.
(
*
mdag
.
ProtoNode
)
if
!
ok
{
return
mdag
.
ErrNotProtobuf
}
pb
:=
new
(
ftpb
.
Data
)
err
=
proto
.
Unmarshal
(
nxtpb
.
Data
(),
pb
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"incorrectly formatted protobuf: %s"
,
err
)
}
switch
nxt
:=
nxt
.
(
type
)
{
case
*
mdag
.
ProtoNode
:
pb
:=
new
(
ftpb
.
Data
)
err
=
proto
.
Unmarshal
(
nxt
.
Data
(),
pb
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"incorrectly formatted protobuf: %s"
,
err
)
}
switch
pb
.
GetType
()
{
case
ftpb
.
Data_Directory
:
// A directory should not exist within a file
return
ft
.
ErrInvalidDirLocation
case
ftpb
.
Data_File
:
dr
.
buf
=
NewDataFileReader
(
dr
.
ctx
,
nxtpb
,
pb
,
dr
.
serv
)
return
nil
case
ftpb
.
Data_Raw
:
dr
.
buf
=
NewRSNCFromBytes
(
pb
.
GetData
())
switch
pb
.
GetType
()
{
case
ftpb
.
Data_Directory
:
// A directory should not exist within a file
return
ft
.
ErrInvalidDirLocation
case
ftpb
.
Data_File
:
dr
.
buf
=
NewDataFileReader
(
dr
.
ctx
,
nxt
,
pb
,
dr
.
serv
)
return
nil
case
ftpb
.
Data_Raw
:
dr
.
buf
=
NewRSNCFromBytes
(
pb
.
GetData
())
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
.
ErrUnrecognizedType
}
case
*
mdag
.
RawNode
:
dr
.
buf
=
NewRSNCFromBytes
(
nxt
.
RawData
())
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
.
ErrUnrecognizedType
return
errors
.
New
(
"unrecognized node type in DagReader"
)
}
}
...
...
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