mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-26 12:57:44 +08:00
(might as well do this at the same time) License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
38 lines
898 B
Go
38 lines
898 B
Go
package coredag
|
|
|
|
import (
|
|
"io"
|
|
"io/ioutil"
|
|
"math"
|
|
|
|
"gx/ipfs/QmXyuFW7at4r9dxRAbrPU9JpHW5aqngAFyxvyhvYjzxRKS/go-merkledag"
|
|
|
|
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
|
|
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
|
|
ipld "gx/ipfs/QmR7TcHkR9nxkUorfi8XMTAMLUK7GiP64TWWBzY3aacc1o/go-ipld-format"
|
|
block "gx/ipfs/QmRcHuYzAyswytBuMF78rj3LTChYszomRFXNg4685ZN1WM/go-block-format"
|
|
)
|
|
|
|
func rawRawParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
|
|
if mhType == math.MaxUint64 {
|
|
mhType = mh.SHA2_256
|
|
}
|
|
|
|
data, err := ioutil.ReadAll(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
h, err := mh.Sum(data, mhType, mhLen)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
c := cid.NewCidV1(cid.Raw, h)
|
|
blk, err := block.NewBlockWithCid(data, c)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
nd := &merkledag.RawNode{Block: blk}
|
|
return []ipld.Node{nd}, nil
|
|
}
|