Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
files returned from unixfsnode should be traversable back to their su…
…bstrate
  • Loading branch information
willscott committed Aug 25, 2023
commit a09e25d6b068a96f3a83d0c007e228403d1d9b4d
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