Skip to content

Commit 279d875

Browse files
willscottrvagg
authored andcommitted
files returned from unixfsnode should be traversable back to their substrate
1 parent e27c473 commit 279d875

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

file/file.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"io"
66

77
"github.com/ipld/go-ipld-prime"
8+
"github.com/ipld/go-ipld-prime/adl"
9+
"github.com/ipld/go-ipld-prime/datamodel"
810
)
911

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

5557
// A LargeBytesNode is an ipld.Node that can be streamed over. It is guaranteed to have a Bytes type.
5658
type LargeBytesNode interface {
57-
ipld.Node
59+
adl.ADL
5860
AsLargeBytes() (io.ReadSeeker, error)
5961
}
6062

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

71+
func (f *singleNodeFile) Substrate() datamodel.Node {
72+
return f.Node
73+
}
74+
6975
type singleNodeReader struct {
7076
ipld.Node
7177
offset int

file/shard.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/ipfs/go-unixfsnode/data"
1010
dagpb "github.com/ipld/go-codec-dagpb"
1111
"github.com/ipld/go-ipld-prime"
12+
"github.com/ipld/go-ipld-prime/adl"
1213
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
1314
"github.com/ipld/go-ipld-prime/node/basicnode"
1415
"github.com/multiformats/go-multicodec"
@@ -24,7 +25,7 @@ type shardNodeFile struct {
2425
unpackLk sync.Once
2526
}
2627

27-
var _ ipld.Node = (*shardNodeFile)(nil)
28+
var _ adl.ADL = (*shardNodeFile)(nil)
2829

2930
type shardNodeReader struct {
3031
*shardNodeFile
@@ -233,6 +234,10 @@ func (s *shardNodeFile) AsLargeBytes() (io.ReadSeeker, error) {
233234
return &shardNodeReader{s, nil, 0, 0}, nil
234235
}
235236

237+
func (s *shardNodeFile) Substrate() ipld.Node {
238+
return s.substrate
239+
}
240+
236241
func protoFor(link ipld.Link) ipld.NodePrototype {
237242
if lc, ok := link.(cidlink.Link); ok {
238243
if lc.Cid.Prefix().Codec == uint64(multicodec.DagPb) {

0 commit comments

Comments
 (0)