Skip to content

Commit

Permalink
files returned from unixfsnode should be traversable back to their su…
Browse files Browse the repository at this point in the history
…bstrate
  • Loading branch information
willscott authored and rvagg committed Aug 25, 2023
1 parent e27c473 commit 279d875
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io"

"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/adl"
"github.com/ipld/go-ipld-prime/datamodel"
)

// NewUnixFSFile attempts to construct an ipld node from the base protobuf node representing the
Expand Down Expand Up @@ -54,7 +56,7 @@ func NewUnixFSFileWithPreload(ctx context.Context, substrate ipld.Node, lsys *ip

// A LargeBytesNode is an ipld.Node that can be streamed over. It is guaranteed to have a Bytes type.
type LargeBytesNode interface {
ipld.Node
adl.ADL
AsLargeBytes() (io.ReadSeeker, error)
}

Expand All @@ -66,6 +68,10 @@ func (f *singleNodeFile) AsLargeBytes() (io.ReadSeeker, error) {
return &singleNodeReader{f, 0}, nil
}

func (f *singleNodeFile) Substrate() datamodel.Node {
return f.Node
}

type singleNodeReader struct {
ipld.Node
offset int
Expand Down
7 changes: 6 additions & 1 deletion file/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ipfs/go-unixfsnode/data"
dagpb "github.com/ipld/go-codec-dagpb"
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/adl"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipld/go-ipld-prime/node/basicnode"
"github.com/multiformats/go-multicodec"
Expand All @@ -24,7 +25,7 @@ type shardNodeFile struct {
unpackLk sync.Once
}

var _ ipld.Node = (*shardNodeFile)(nil)
var _ adl.ADL = (*shardNodeFile)(nil)

type shardNodeReader struct {
*shardNodeFile
Expand Down Expand Up @@ -233,6 +234,10 @@ func (s *shardNodeFile) AsLargeBytes() (io.ReadSeeker, error) {
return &shardNodeReader{s, nil, 0, 0}, nil
}

func (s *shardNodeFile) Substrate() ipld.Node {
return s.substrate
}

func protoFor(link ipld.Link) ipld.NodePrototype {
if lc, ok := link.(cidlink.Link); ok {
if lc.Cid.Prefix().Codec == uint64(multicodec.DagPb) {
Expand Down

0 comments on commit 279d875

Please sign in to comment.