From e7a3eae5cf0d2e2c9a71cad0d3f2c43335f02229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 22 Apr 2024 22:22:14 +0200 Subject: [PATCH] Make ReadFooterDataFromBlob test-only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It has no non-test users any more, so decrease the size of this package (relevant to non-c/storage callers of c/image). Should not change behavior. Signed-off-by: Miloslav Trmač --- pkg/chunked/internal/compression.go | 23 -------------------- pkg/chunked/internal/compression_test.go | 27 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/pkg/chunked/internal/compression.go b/pkg/chunked/internal/compression.go index 53fb98ae2d..14897e5c20 100644 --- a/pkg/chunked/internal/compression.go +++ b/pkg/chunked/internal/compression.go @@ -8,7 +8,6 @@ import ( "archive/tar" "bytes" "encoding/binary" - "errors" "fmt" "io" "time" @@ -251,25 +250,3 @@ func ReadFooterDataFromAnnotations(annotations map[string]string) (ZstdChunkedFo } return footerData, nil } - -// ReadFooterDataFromBlob reads the zstd:chunked footer from the binary buffer. -func ReadFooterDataFromBlob(footer []byte) (ZstdChunkedFooterData, error) { - var footerData ZstdChunkedFooterData - - if len(footer) < FooterSizeSupported { - return footerData, errors.New("blob too small") - } - footerData.Offset = binary.LittleEndian.Uint64(footer[0:8]) - footerData.LengthCompressed = binary.LittleEndian.Uint64(footer[8:16]) - footerData.LengthUncompressed = binary.LittleEndian.Uint64(footer[16:24]) - footerData.ManifestType = binary.LittleEndian.Uint64(footer[24:32]) - footerData.OffsetTarSplit = binary.LittleEndian.Uint64(footer[32:40]) - footerData.LengthCompressedTarSplit = binary.LittleEndian.Uint64(footer[40:48]) - footerData.LengthUncompressedTarSplit = binary.LittleEndian.Uint64(footer[48:56]) - - // the magic number is stored in the last 8 bytes - if !bytes.Equal(ZstdChunkedFrameMagic, footer[len(footer)-len(ZstdChunkedFrameMagic):]) { - return footerData, errors.New("invalid magic number") - } - return footerData, nil -} diff --git a/pkg/chunked/internal/compression_test.go b/pkg/chunked/internal/compression_test.go index 9d4e60d47c..26c32e5382 100644 --- a/pkg/chunked/internal/compression_test.go +++ b/pkg/chunked/internal/compression_test.go @@ -4,6 +4,9 @@ package internal import ( + "bytes" + "encoding/binary" + "errors" "testing" "github.com/stretchr/testify/assert" @@ -23,10 +26,32 @@ func TestGenerateAndReadFooter(t *testing.T) { b := footerDataToBlob(footer) assert.Len(t, b, FooterSizeSupported) - footer2, err := ReadFooterDataFromBlob(b) + footer2, err := readFooterDataFromBlob(b) if err != nil { t.Fatal(err) } assert.Equal(t, footer, footer2) } + +// readFooterDataFromBlob reads the zstd:chunked footer from the binary buffer. +func readFooterDataFromBlob(footer []byte) (ZstdChunkedFooterData, error) { + var footerData ZstdChunkedFooterData + + if len(footer) < FooterSizeSupported { + return footerData, errors.New("blob too small") + } + footerData.Offset = binary.LittleEndian.Uint64(footer[0:8]) + footerData.LengthCompressed = binary.LittleEndian.Uint64(footer[8:16]) + footerData.LengthUncompressed = binary.LittleEndian.Uint64(footer[16:24]) + footerData.ManifestType = binary.LittleEndian.Uint64(footer[24:32]) + footerData.OffsetTarSplit = binary.LittleEndian.Uint64(footer[32:40]) + footerData.LengthCompressedTarSplit = binary.LittleEndian.Uint64(footer[40:48]) + footerData.LengthUncompressedTarSplit = binary.LittleEndian.Uint64(footer[48:56]) + + // the magic number is stored in the last 8 bytes + if !bytes.Equal(ZstdChunkedFrameMagic, footer[len(footer)-len(ZstdChunkedFrameMagic):]) { + return footerData, errors.New("invalid magic number") + } + return footerData, nil +}