1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-08-06 19:44:01 +08:00
Files
kubo/core/coredag/cbor.go
Jakub Sztandera 42e191c017 gx: unrewrite
License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
2019-03-05 18:33:56 +01:00

33 lines
601 B
Go

package coredag
import (
"io"
"io/ioutil"
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 := ioutil.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
}