-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package testutil | ||
|
||
import ( | ||
"hash/crc64" | ||
"io" | ||
) | ||
|
||
const bufSize = 4 << 16 | ||
|
||
var polynomial = crc64.ECMA | ||
Check failure on line 10 in pkg/testutil/checksum.go GitHub Actions / Run Go tests
Check failure on line 10 in pkg/testutil/checksum.go GitHub Actions / Run Linters and Checkers
|
||
|
||
// ChecksumReader returns the checksum (CRC-64) of the contents of reader. | ||
func ChecksumReader(reader io.Reader) (uint64, error) { | ||
buf := make([]byte, bufSize) | ||
Check failure on line 14 in pkg/testutil/checksum.go GitHub Actions / Run Go tests
Check failure on line 14 in pkg/testutil/checksum.go GitHub Actions / Run Linters and Checkers
|
||
var val uint64 | ||
for { | ||
n, err := r.Read(b) | ||
Check failure on line 17 in pkg/testutil/checksum.go GitHub Actions / Run Go tests
Check failure on line 17 in pkg/testutil/checksum.go GitHub Actions / Run Go tests
Check failure on line 17 in pkg/testutil/checksum.go GitHub Actions / Run Linters and Checkers
Check failure on line 17 in pkg/testutil/checksum.go GitHub Actions / Run Linters and Checkers
Check failure on line 17 in pkg/testutil/checksum.go GitHub Actions / Test unified gc
|
||
if err != nil { | ||
if err == io.EOF { | ||
return val, nil | ||
} | ||
return val, err | ||
} | ||
if n == 0 { | ||
return val, nil | ||
} | ||
val = crc64.Update(val, polynomial, b[:n]) | ||
Check failure on line 27 in pkg/testutil/checksum.go GitHub Actions / Run Go tests
Check failure on line 27 in pkg/testutil/checksum.go GitHub Actions / Run Go tests
Check failure on line 27 in pkg/testutil/checksum.go GitHub Actions / Run Linters and Checkers
Check failure on line 27 in pkg/testutil/checksum.go GitHub Actions / Run Linters and Checkers
Check failure on line 27 in pkg/testutil/checksum.go GitHub Actions / Test unified gc
|
||
} | ||
} |