Documentation
¶
Overview ¶
Package digestpipe is the digest-verifying stream tee.
A Writer wraps an underlying io.Writer (typically a *os.File or an io.MultiWriter that fans out to disk + a peer response) and computes a sha256 digest incrementally as bytes flow through. After the stream ends the caller invokes Verify(d) to check that the computed digest matches an expected value.
The original the design doc design called for a "digest-verifying stream tee (containerd ↔ peer ↔ cache)". This package is the primitive on which containerdstore.Writer's digest verification is built; it can also be composed directly by callers that already own the destination io.Writer (peer transfer, HTTP response). The tee itself is just bytes-through; Verify is the authoritative go/no-go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDigestMismatch = errors.New("digestpipe: digest mismatch")
ErrDigestMismatch is returned by Verify when the computed digest does not match the expected one. Callers can errors.Is against this sentinel for retry/fail-class logic.
Functions ¶
This section is empty.
Types ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is an io.Writer that forwards bytes to a destination while accumulating a sha256 digest. Use one Writer per stream; not safe for concurrent Write/Verify.
func New ¶
New returns a Writer that forwards bytes to dst while accumulating a sha256 digest. dst must be non-nil.
func (*Writer) Sum ¶
Sum returns the lowercase hex sha256 of bytes seen so far. Calling Sum does not advance or reset internal state and is safe to invoke repeatedly.
func (*Writer) Verify ¶
Verify returns nil when the computed sha256 matches want. On mismatch it returns an error that wraps ErrDigestMismatch and includes both the expected and observed digests in the message.