mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 05:52:20 +08:00
address comments from PR
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package blocks
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
||||
@ -18,6 +19,16 @@ func NewBlock(data []byte) *Block {
|
||||
return &Block{Data: data, Multihash: u.Hash(data)}
|
||||
}
|
||||
|
||||
func NewBlockWithHash(data []byte, h mh.Multihash) (*Block, error) {
|
||||
if u.Debug {
|
||||
chk := u.Hash(data)
|
||||
if string(chk) != string(h) {
|
||||
return nil, errors.New("Data did not match given hash!")
|
||||
}
|
||||
}
|
||||
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)
|
||||
|
Reference in New Issue
Block a user