kubo/core/coredag/cbor.go
Jorropo a433064d72
chore: replace ioutil with io and os (#8969)
Co-authored-by: Håvard Anda Estensen <haavard.ae@gmail.com>
2022-06-14 12:37:02 -04:00

32 lines
584 B
Go

package coredag
import (
"io"
ipldcbor "github.com/ipfs/go-ipld-cbor"
ipld "github.com/ipfs/go-ipld-format"
)
func cborJSONParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
nd, err := ipldcbor.FromJSON(r, mhType, mhLen)
if err != nil {
return nil, err
}
return []ipld.Node{nd}, nil
}
func cborRawParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
nd, err := ipldcbor.Decode(data, mhType, mhLen)
if err != nil {
return nil, err
}
return []ipld.Node{nd}, nil
}