1
0
mirror of https://github.com/containers/image.git synced 2025-04-18 19:44:05 +03:00

Reorganize tarballReference.NewImageSource a bit

Move the layerType value closer to the code that
actually knows the format.

Don't allocate/initialize a sha256 state if we don't
know we are going to need it.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač 2025-03-19 17:35:22 +01:00
parent 0cf7de7e11
commit d79d5ff9c2

View File

@ -82,19 +82,19 @@ func (r *tarballReference) NewImageSource(ctx context.Context, sys *types.System
}
}
// Default to assuming the layer is compressed.
layerType := imgspecv1.MediaTypeImageLayerGzip
// Set up to digest the file as it is.
blobIDdigester := digest.Canonical.Digester()
reader = io.TeeReader(reader, blobIDdigester.Hash())
var layerType string
var diffIDdigester digest.Digester
// Set up to digest the file after we maybe decompress it.
diffIDdigester := digest.Canonical.Digester()
uncompressed, err := pgzip.NewReader(reader)
if err == nil {
// It is compressed, so the diffID is the digest of the uncompressed version
diffIDdigester = digest.Canonical.Digester()
reader = io.TeeReader(uncompressed, diffIDdigester.Hash())
layerType = imgspecv1.MediaTypeImageLayerGzip
} else {
// It is not compressed, so the diffID and the blobID are going to be the same
diffIDdigester = blobIDdigester