Skip to content

Commit

Permalink
address comments from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Nov 1, 2014
1 parent d1dd0be commit 7e73676
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions blocks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package blocks

import (
"errors"
"fmt"

mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
Expand All @@ -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)
Expand Down

0 comments on commit 7e73676

Please sign in to comment.