From 7e7367637a45c7bba657f1f96a5821d22ef0a000 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Wed, 29 Oct 2014 18:34:53 +0000 Subject: [PATCH] address comments from PR --- blocks.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/blocks.go b/blocks.go index 9bf556f..b87cf5a 100644 --- a/blocks.go +++ b/blocks.go @@ -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)