Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

files returned from unixfsnode should be traversable to their substrate #67

Merged
merged 1 commit into from
Aug 25, 2023
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
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