fix: store buf outside for loop

This commit is contained in:
Derrick Hammer 2024-02-18 02:29:15 -05:00
parent bff0981731
commit 938b6cdf9e
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 3 additions and 1 deletions

View File

@ -80,8 +80,9 @@ func Hash(r io.Reader) (*Result, error) {
reader := bufio.NewReaderSize(r, bufSize)
var totalReadSize int
for {
buf := make([]byte, bufSize)
for {
n, err := reader.Read(buf)
if err != nil {
if err == io.EOF {
@ -99,6 +100,7 @@ func Hash(r io.Reader) (*Result, error) {
if n == bufSize && float64(bufSize) < maxSize {
// If buffer was fully used, consider increasing buffer size
bufSize = int(math.Min(float64(bufSize*2), float64(maxSize))) // Double the buffer size, up to a maximum
buf = make([]byte, bufSize) // Apply new buffer size
reader = bufio.NewReaderSize(r, bufSize) // Apply new buffer size
}
}