Commit 64720f3b authored by Jeromy's avatar Jeromy

raw dag: make raw nodes work in cat and get, add tests

License: MIT
Signed-off-by: default avatarJeromy <why@ipfs.io>
parent f47e36a5
...@@ -129,13 +129,10 @@ func (dr *DagReader) precalcNextBuf(ctx context.Context) error { ...@@ -129,13 +129,10 @@ func (dr *DagReader) precalcNextBuf(ctx context.Context) error {
} }
dr.linkPosition++ dr.linkPosition++
nxtpb, ok := nxt.(*mdag.ProtoNode) switch nxt := nxt.(type) {
if !ok { case *mdag.ProtoNode:
return mdag.ErrNotProtobuf
}
pb := new(ftpb.Data) pb := new(ftpb.Data)
err = proto.Unmarshal(nxtpb.Data(), pb) err = proto.Unmarshal(nxt.Data(), pb)
if err != nil { if err != nil {
return fmt.Errorf("incorrectly formatted protobuf: %s", err) return fmt.Errorf("incorrectly formatted protobuf: %s", err)
} }
...@@ -145,7 +142,7 @@ func (dr *DagReader) precalcNextBuf(ctx context.Context) error { ...@@ -145,7 +142,7 @@ func (dr *DagReader) precalcNextBuf(ctx context.Context) error {
// A directory should not exist within a file // A directory should not exist within a file
return ft.ErrInvalidDirLocation return ft.ErrInvalidDirLocation
case ftpb.Data_File: case ftpb.Data_File:
dr.buf = NewDataFileReader(dr.ctx, nxtpb, pb, dr.serv) dr.buf = NewDataFileReader(dr.ctx, nxt, pb, dr.serv)
return nil return nil
case ftpb.Data_Raw: case ftpb.Data_Raw:
dr.buf = NewRSNCFromBytes(pb.GetData()) dr.buf = NewRSNCFromBytes(pb.GetData())
...@@ -157,6 +154,12 @@ func (dr *DagReader) precalcNextBuf(ctx context.Context) error { ...@@ -157,6 +154,12 @@ func (dr *DagReader) precalcNextBuf(ctx context.Context) error {
default: default:
return ft.ErrUnrecognizedType return ft.ErrUnrecognizedType
} }
case *mdag.RawNode:
dr.buf = NewRSNCFromBytes(nxt.RawData())
return nil
default:
return errors.New("unrecognized node type in DagReader")
}
} }
// Size return the total length of the data from the DAG structured file. // Size return the total length of the data from the DAG structured file.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment