digestpipe

package
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 7 Imported by: 0

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

View Source
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

func New(dst io.Writer) *Writer

New returns a Writer that forwards bytes to dst while accumulating a sha256 digest. dst must be non-nil.

func (*Writer) Sum

func (w *Writer) Sum() string

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

func (w *Writer) Verify(want digest.Digest) error

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.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write forwards p to the underlying destination, then folds the successfully-written prefix p[:n] into the running hash. Bytes that the destination rejected (n < len(p)) are not folded in, so callers that retry must restart from a fresh Writer.

func (*Writer) Written

func (w *Writer) Written() int64

Written returns the number of bytes successfully forwarded so far.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL