Files
potency/bodyintercept.go
Ian Gulliver cb9d3aef62 Initial commit
2023-04-20 17:54:42 +00:00

31 lines
481 B
Go

package potency
import (
"crypto/sha256"
"hash"
"io"
)
type bodyIntercept struct {
source io.ReadCloser
sha256 hash.Hash
}
func newBodyIntercept(source io.ReadCloser) *bodyIntercept {
return &bodyIntercept{
source: source,
sha256: sha256.New(),
}
}
func (bi *bodyIntercept) Read(p []byte) (int, error) {
numBytes, err := bi.source.Read(p)
bi.sha256.Write(p[:numBytes])
return numBytes, err
}
func (bi *bodyIntercept) Close() error {
return bi.source.Close()
}