raw.go 1.07 KB
Newer Older
1 2 3 4 5
package merkledag

import (
	"github.com/ipfs/go-ipfs/blocks"

6 7
	node "gx/ipfs/QmU7bFWQ793qmvNy7outdCaMfSDNk8uqhx4VNrxYj5fj5g/go-ipld-node"
	cid "gx/ipfs/QmXfiyr2RWEXpVDdaYnD2HNiBk6UBddsvEP4RPfXb6nGqY/go-cid"
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
	u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
)

type RawNode struct {
	blocks.Block
}

func NewRawNode(data []byte) *RawNode {
	h := u.Hash(data)
	c := cid.NewCidV1(cid.Raw, h)
	blk, _ := blocks.NewBlockWithCid(data, c)

	return &RawNode{blk}
}

func (rn *RawNode) Links() []*node.Link {
	return nil
}

27 28 29 30 31
func (rn *RawNode) ResolveLink(path []string) (*node.Link, []string, error) {
	return nil, nil, ErrLinkNotFound
}

func (rn *RawNode) Resolve(path []string) (interface{}, []string, error) {
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
	return nil, nil, ErrLinkNotFound
}

func (rn *RawNode) Tree() []string {
	return nil
}

func (rn *RawNode) Size() (uint64, error) {
	return uint64(len(rn.RawData())), nil
}

func (rn *RawNode) Stat() (*node.NodeStat, error) {
	return &node.NodeStat{
		CumulativeSize: len(rn.RawData()),
		DataSize:       len(rn.RawData()),
	}, nil
}

var _ node.Node = (*RawNode)(nil)