diff --git a/bzz/bzzhash/bzzhash.go b/bzz/bzzhash/bzzhash.go index 47086063a8..f10e90f056 100644 --- a/bzz/bzzhash/bzzhash.go +++ b/bzz/bzzhash/bzzhash.go @@ -22,7 +22,17 @@ func main() { stat, _ := f.Stat() sr := io.NewSectionReader(f, 0, stat.Size()) - hash := bzz.GetDPAhash(sr, nil) - - fmt.Printf("%064x\n", hash) + chunker := &bzz.TreeChunker{ + Branches: 128, + } + chunker.Init() + hash := make([]byte, chunker.HashSize()) + errC := chunker.Split(hash, sr, nil) + err, ok := <-errC + if err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) + } + if !ok { + fmt.Printf("%064x\n", hash) + } } diff --git a/bzz/chunker.go b/bzz/chunker.go index 35316bb378..2f4b554c76 100644 --- a/bzz/chunker.go +++ b/bzz/chunker.go @@ -111,6 +111,10 @@ func (self *TreeChunker) Init() { } +func (self *TreeChunker) HashSize() int64 { + return self.hashSize +} + type Chunk struct { Data SectionReader // nil if request, to be supplied by dpa Size int64 // size of the data covered by the subtree encoded in this chunk @@ -258,7 +262,9 @@ func (self *TreeChunker) split(depth int, treeSize int64, key Key, data SectionR } } // send off new chunk to storage - chunkC <- newChunk + if chunkC != nil { + chunkC <- newChunk + } // report hash of this chunk one level up (keys corresponds to the proper subslice of the parent chunk)x copy(key, hash)