mirror of
https://github.com/ipfs/kubo.git
synced 2025-08-06 11:31:54 +08:00
38 lines
898 B
Go
38 lines
898 B
Go
package coredag
|
|
|
|
import (
|
|
"io"
|
|
"io/ioutil"
|
|
"math"
|
|
|
|
"gx/ipfs/QmRiQCJZ91B7VNmLvA6sxzDuBJGSojS3uXHHVuNr3iueNZ/go-merkledag"
|
|
|
|
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
|
|
block "gx/ipfs/QmWAzSEoqZ6xU6pu8yL8e5WaMb7wtbfbhhN4p1DknUPtr3/go-block-format"
|
|
ipld "gx/ipfs/QmX5CsuHyVZeTLxgRSYkgLSDQKb9UjE8xnhQzCEJWWWFsC/go-ipld-format"
|
|
cid "gx/ipfs/QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb/go-cid"
|
|
)
|
|
|
|
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
|
|
}
|