-// Read from the underlying reader, update the hashing function, and pass the
-// results through. Will return BadChecksum on the last read instead of EOF if
-// the checksum doesn't match.
-func (this HashCheckingReader) Read(p []byte) (n int, err error) {
- n, err = this.Reader.Read(p)
- if err == nil {
- this.Hash.Write(p[:n])
- } else if err == io.EOF {
- sum := this.Hash.Sum(make([]byte, 0, this.Hash.Size()))
- if fmt.Sprintf("%x", sum) != this.Check {
+// Reads from the underlying reader, update the hashing function, and
+// pass the results through. Returns BadChecksum (instead of EOF) on
+// the last read if the checksum doesn't match.
+func (hcr HashCheckingReader) Read(p []byte) (n int, err error) {
+ n, err = hcr.Reader.Read(p)
+ if n > 0 {
+ hcr.Hash.Write(p[:n])
+ }
+ if err == io.EOF {
+ sum := hcr.Hash.Sum(nil)
+ if fmt.Sprintf("%x", sum) != hcr.Check {