1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-09 19:32:24 +08:00
Files
kubo/blocks/blocks.go

28 lines
616 B
Go

package blocks
import (
u "github.com/jbenet/go-ipfs/util"
mh "github.com/jbenet/go-multihash"
)
// Block is the ipfs blocks service. It is the way
// to retrieve blocks by the higher level ipfs modules
type Block struct {
Multihash mh.Multihash
Data []byte
}
// NewBlock creates a Block object from opaque data. It will hash the data.
func NewBlock(data []byte) (*Block, error) {
h, err := u.Hash(data)
if err != nil {
return nil, err
}
return &Block{Data: data, Multihash: h}, nil
}
// Key returns the block's Multihash as a Key value.
func (b *Block) Key() u.Key {
return u.Key(b.Multihash)
}