MCPcopy Index your code
hub / github.com/aptly-dev/aptly / DownloadTryCompression

Function DownloadTryCompression

http/compression.go:42–95  ·  view source on GitHub ↗

DownloadTryCompression tries to download from URL .bz2, .gz and raw extension until it finds existing file.

(ctx context.Context, downloader aptly.Downloader, baseURL *url.URL, path string, expectedChecksums map[string]utils.ChecksumInfo, ignoreMismatch bool)

Source from the content-addressed store, hash-verified

40// DownloadTryCompression tries to download from URL .bz2, .gz and raw extension until
41// it finds existing file.
42func DownloadTryCompression(ctx context.Context, downloader aptly.Downloader, baseURL *url.URL, path string, expectedChecksums map[string]utils.ChecksumInfo, ignoreMismatch bool) (io.Reader, *os.File, error) {
43 var err error
44
45 for _, method := range compressionMethods {
46 var file *os.File
47
48 tryPath := path + method.extenstion
49 foundChecksum := false
50
51 bestSuffix := ""
52
53 for suffix := range expectedChecksums {
54 if strings.HasSuffix(tryPath, suffix) {
55 foundChecksum = true
56 if len(suffix) > len(bestSuffix) {
57 bestSuffix = suffix
58 }
59 }
60 }
61
62 tryURL := baseURL.ResolveReference(&url.URL{Path: tryPath})
63
64 if foundChecksum {
65 expected := expectedChecksums[bestSuffix]
66 file, err = DownloadTempWithChecksum(ctx, downloader, tryURL.String(), &expected, ignoreMismatch)
67 } else {
68 if !ignoreMismatch {
69 continue
70 }
71
72 file, err = DownloadTemp(ctx, downloader, tryURL.String())
73 }
74
75 if err != nil {
76 if err1, ok := err.(*Error); ok && (err1.Code == 404 || err1.Code == 403) {
77 continue
78 }
79 return nil, nil, err
80 }
81
82 var uncompressed io.Reader
83 uncompressed, err = method.transformation(file)
84 if err != nil {
85 return nil, nil, err
86 }
87
88 return uncompressed, file, err
89 }
90
91 if err == nil {
92 return nil, nil, &NoCandidateFoundError{URL: baseURL.ResolveReference(&url.URL{Path: path})}
93 }
94 return nil, nil, err
95}

Calls 3

DownloadTempWithChecksumFunction · 0.85
DownloadTempFunction · 0.85
StringMethod · 0.65