forked from ipfs/kubo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw.go
37 lines (31 loc) · 864 Bytes
/
raw.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package coredag
import (
"io"
"io/ioutil"
"math"
"github.com/ipfs/go-ipfs/merkledag"
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
block "gx/ipfs/QmTRCUvZLiir12Qr6MV3HKfKMHX8Nf1Vddn6t2g5nsQSb9/go-block-format"
ipld "gx/ipfs/QmWi2BYBL5gJ3CiAiQchg6rn1A8iBsrWy51EYxvHVjFvLb/go-ipld-format"
cid "gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/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
}