mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-28 05:47:51 +08:00
(might as well do this at the same time) License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
33 lines
679 B
Go
33 lines
679 B
Go
package coredag
|
|
|
|
import (
|
|
"io"
|
|
"io/ioutil"
|
|
|
|
ipld "gx/ipfs/QmR7TcHkR9nxkUorfi8XMTAMLUK7GiP64TWWBzY3aacc1o/go-ipld-format"
|
|
ipldcbor "gx/ipfs/QmfVWZztCxyZuS5NDBV1JpmUJiNQKD1MEnbWbqTTzZLyP7/go-ipld-cbor"
|
|
)
|
|
|
|
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
|
|
}
|