blocks.go 538 Bytes
Newer Older
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
1 2 3
package blocks

import (
4
	mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
5
	u "github.com/jbenet/go-ipfs/util"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
6 7
)

Jeromy's avatar
Jeromy committed
8
// Block is a singular block of data in ipfs
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
9 10 11 12 13
type Block struct {
	Multihash mh.Multihash
	Data      []byte
}

Juan Batiz-Benet's avatar
go lint  
Juan Batiz-Benet committed
14
// NewBlock creates a Block object from opaque data. It will hash the data.
15 16
func NewBlock(data []byte) *Block {
	return &Block{Data: data, Multihash: u.Hash(data)}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
17 18
}

Juan Batiz-Benet's avatar
go lint  
Juan Batiz-Benet committed
19
// Key returns the block's Multihash as a Key value.
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
20 21 22
func (b *Block) Key() u.Key {
	return u.Key(b.Multihash)
}