Skip to content

Commit

Permalink
Inline ReadFooterDataFromAnnotations into the only caller
Browse files Browse the repository at this point in the history
Again, decrease the size of the compression code for c/image.

We will simplify this further immediately.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Apr 22, 2024
1 parent e7a3eae commit 2c240ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
11 changes: 9 additions & 2 deletions pkg/chunked/compression_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,17 @@ func readZstdChunkedManifest(blobStream ImageSourceSeekable, tocDigest digest.Di
return nil, nil, 0, fmt.Errorf("%q annotation missing", internal.ManifestInfoKey)
}

footerData, err := internal.ReadFooterDataFromAnnotations(annotations)
if err != nil {
var footerData internal.ZstdChunkedFooterData

if _, err := fmt.Sscanf(offsetMetadata, "%d:%d:%d:%d", &footerData.Offset, &footerData.LengthCompressed, &footerData.LengthUncompressed, &footerData.ManifestType); err != nil {
return nil, nil, 0, err
}
if tarSplitInfoKeyAnnotation, found := annotations[internal.TarSplitInfoKey]; found {
if _, err := fmt.Sscanf(tarSplitInfoKeyAnnotation, "%d:%d:%d", &footerData.OffsetTarSplit, &footerData.LengthCompressedTarSplit, &footerData.LengthUncompressedTarSplit); err != nil {
return nil, nil, 0, err
}
footerData.ChecksumAnnotationTarSplit = annotations[internal.TarSplitChecksumKey]
}

if footerData.ManifestType != internal.ManifestTypeCRFS {
return nil, nil, 0, errors.New("invalid manifest type")
Expand Down
19 changes: 0 additions & 19 deletions pkg/chunked/internal/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,22 +231,3 @@ func footerDataToBlob(footer ZstdChunkedFooterData) []byte {

return manifestDataLE
}

// ReadFooterDataFromAnnotations reads the zstd:chunked footer data from the given annotations.
func ReadFooterDataFromAnnotations(annotations map[string]string) (ZstdChunkedFooterData, error) {
var footerData ZstdChunkedFooterData

offsetMetadata := annotations[ManifestInfoKey]

if _, err := fmt.Sscanf(offsetMetadata, "%d:%d:%d:%d", &footerData.Offset, &footerData.LengthCompressed, &footerData.LengthUncompressed, &footerData.ManifestType); err != nil {
return footerData, err
}

if tarSplitInfoKeyAnnotation, found := annotations[TarSplitInfoKey]; found {
if _, err := fmt.Sscanf(tarSplitInfoKeyAnnotation, "%d:%d:%d", &footerData.OffsetTarSplit, &footerData.LengthCompressedTarSplit, &footerData.LengthUncompressedTarSplit); err != nil {
return footerData, err
}
footerData.ChecksumAnnotationTarSplit = annotations[TarSplitChecksumKey]
}
return footerData, nil
}

0 comments on commit 2c240ca

Please sign in to comment.