refactor: have bao hash return totalReadSize

This commit is contained in:
Derrick Hammer 2024-02-09 15:22:46 -05:00
parent fc61da0d01
commit 2a1abb852b
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 4 additions and 4 deletions

View File

@ -73,7 +73,7 @@ func Shutdown() {
client.Kill() client.Kill()
} }
func Hash(r io.Reader) (*Result, error) { func Hash(r io.Reader) (*Result, int, error) {
hasherId := bao.NewHasher() hasherId := bao.NewHasher()
initialSize := 4 * units.KiB initialSize := 4 * units.KiB
maxSize := 3.5 * units.MiB maxSize := 3.5 * units.MiB
@ -89,12 +89,12 @@ func Hash(r io.Reader) (*Result, error) {
if err == io.EOF { if err == io.EOF {
break break
} }
return nil, err return nil, 0, err
} }
totalReadSize += n totalReadSize += n
if !bao.Hash(hasherId, buf[:n]) { if !bao.Hash(hasherId, buf[:n]) {
return nil, errors.New("hashing failed") return nil, 0, errors.New("hashing failed")
} }
// Adaptively adjust buffer size based on read patterns // Adaptively adjust buffer size based on read patterns
@ -107,5 +107,5 @@ func Hash(r io.Reader) (*Result, error) {
result := bao.Finish(hasherId) result := bao.Finish(hasherId)
return &result, nil return &result, totalReadSize, nil
} }