Commit 0271059b authored by Lucas Molas's avatar Lucas Molas

unixfs: split `precalcNextBuf`

Create new `loadBufNode` function to handle the `buf` logic which is unrelated
to the main `precalcNextBuf` logic of processing promises to fetch nodes.

License: MIT
Signed-off-by: default avatarLucas Molas <schomatis@gmail.com>
parent 5d5060dd
...@@ -98,16 +98,20 @@ func (dr *PBDagReader) precalcNextBuf(ctx context.Context) error { ...@@ -98,16 +98,20 @@ func (dr *PBDagReader) precalcNextBuf(ctx context.Context) error {
dr.promises[dr.linkPosition] = nil dr.promises[dr.linkPosition] = nil
dr.linkPosition++ 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: case *mdag.ProtoNode:
fsNode, err := ft.FSNodeFromBytes(nxt.Data()) fsNode, err := ft.FSNodeFromBytes(node.Data())
if err != nil { if err != nil {
return fmt.Errorf("incorrectly formatted protobuf: %s", err) return fmt.Errorf("incorrectly formatted protobuf: %s", err)
} }
switch fsNode.Type() { switch fsNode.Type() {
case ftpb.Data_File: case ftpb.Data_File:
dr.buf = NewPBFileReader(dr.ctx, nxt, fsNode, dr.serv) dr.buf = NewPBFileReader(dr.ctx, node, fsNode, dr.serv)
return nil return nil
case ftpb.Data_Raw: case ftpb.Data_Raw:
dr.buf = NewBufDagReader(fsNode.Data()) dr.buf = NewBufDagReader(fsNode.Data())
...@@ -116,7 +120,7 @@ func (dr *PBDagReader) precalcNextBuf(ctx context.Context) error { ...@@ -116,7 +120,7 @@ func (dr *PBDagReader) precalcNextBuf(ctx context.Context) error {
return fmt.Errorf("found %s node in unexpected place", fsNode.Type().String()) return fmt.Errorf("found %s node in unexpected place", fsNode.Type().String())
} }
case *mdag.RawNode: case *mdag.RawNode:
dr.buf = NewBufDagReader(nxt.RawData()) dr.buf = NewBufDagReader(node.RawData())
return nil return nil
default: default:
return ErrUnkownNodeType return ErrUnkownNodeType
......
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