moby/internal/testutils/archive.go
Paweł Gronowski 2ef0b53e51
integration/save: Add tests checking OCI archive output
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-02-05 11:17:58 +01:00

24 lines
540 B
Go

package testutils
import (
"io"
"github.com/docker/docker/pkg/archive"
"github.com/opencontainers/go-digest"
)
// UncompressedTarDigest returns the canonical digest of the uncompressed tar stream.
func UncompressedTarDigest(compressedTar io.Reader) (digest.Digest, error) {
rd, err := archive.DecompressStream(compressedTar)
if err != nil {
return "", err
}
defer rd.Close()
digester := digest.Canonical.Digester()
if _, err := io.Copy(digester.Hash(), rd); err != nil {
return "", err
}
return digester.Digest(), nil
}