Skip to content

Commit

Permalink
container: add a helper for test only
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure committed Feb 27, 2025
1 parent 6aa33b1 commit 6d3846a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/container/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,20 @@ func (ctn Writer) toWriter(header header, w io.Writer) (err error) {

return ipld.EncodeStreaming(encoder, node, cbor.Encode)
}

// ToReader convert a container Writer into a Reader.
// Most likely, you only want to use this in tests for convenience.
// This is not optimized and can panic.
func (ctn Writer) ToReader() Reader {
data, err := ctn.ToBytes()
if err != nil {
panic(err)
}

reader, err := FromBytes(data)
if err != nil {
panic(err)
}

return reader
}

0 comments on commit 6d3846a

Please sign in to comment.