From 279d875c5494e8f75f585bf2a460c4ffaab2058e Mon Sep 17 00:00:00 2001 From: Will Scott Date: Fri, 25 Aug 2023 15:37:01 +0200 Subject: [PATCH] files returned from unixfsnode should be traversable back to their substrate --- file/file.go | 8 +++++++- file/shard.go | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/file/file.go b/file/file.go index d971033..422d2ab 100644 --- a/file/file.go +++ b/file/file.go @@ -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 @@ -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) } @@ -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 diff --git a/file/shard.go b/file/shard.go index dc28310..656e91b 100644 --- a/file/shard.go +++ b/file/shard.go @@ -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" @@ -24,7 +25,7 @@ type shardNodeFile struct { unpackLk sync.Once } -var _ ipld.Node = (*shardNodeFile)(nil) +var _ adl.ADL = (*shardNodeFile)(nil) type shardNodeReader struct { *shardNodeFile @@ -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) {