getBlob returns a stream for the specified blob in ref, and the blob’s size (or -1 if unknown). The Digest field in BlobInfo is guaranteed to be provided, Size may be -1 and MediaType may be optionally provided. May update BlobInfoCache, preferably after it knows for certain that a blob truly exists
(ctx context.Context, ref dockerReference, info types.BlobInfo, cache types.BlobInfoCache)
| 1035 | // The Digest field in BlobInfo is guaranteed to be provided, Size may be -1 and MediaType may be optionally provided. |
| 1036 | // May update BlobInfoCache, preferably after it knows for certain that a blob truly exists at a specific location. |
| 1037 | func (c *dockerClient) getBlob(ctx context.Context, ref dockerReference, info types.BlobInfo, cache types.BlobInfoCache) (io.ReadCloser, int64, error) { |
| 1038 | if len(info.URLs) != 0 { |
| 1039 | r, s, err := c.getExternalBlob(ctx, info.URLs) |
| 1040 | if err != nil { |
| 1041 | return nil, 0, err |
| 1042 | } else if r != nil { |
| 1043 | return r, s, nil |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | if err := info.Digest.Validate(); err != nil { // Make sure info.Digest.String() does not contain any unexpected characters |
| 1048 | return nil, 0, err |
| 1049 | } |
| 1050 | path := fmt.Sprintf(blobsPath, reference.Path(ref.ref), info.Digest.String()) |
| 1051 | logrus.Debugf("Downloading %s", path) |
| 1052 | res, err := c.makeRequest(ctx, http.MethodGet, path, nil, nil, v2Auth, nil) |
| 1053 | if err != nil { |
| 1054 | return nil, 0, err |
| 1055 | } |
| 1056 | if res.StatusCode != http.StatusOK { |
| 1057 | err := registryHTTPResponseToError(res) |
| 1058 | res.Body.Close() |
| 1059 | return nil, 0, fmt.Errorf("fetching blob: %w", err) |
| 1060 | } |
| 1061 | cache.RecordKnownLocation(ref.Transport(), bicTransportScope(ref), info.Digest, newBICLocationReference(ref)) |
| 1062 | blobSize, err := getBlobSize(res) |
| 1063 | if err != nil { |
| 1064 | blobSize = -1 |
| 1065 | } |
| 1066 | |
| 1067 | reconnectingReader, err := newBodyReader(ctx, c, path, res.Body) |
| 1068 | if err != nil { |
| 1069 | res.Body.Close() |
| 1070 | return nil, 0, err |
| 1071 | } |
| 1072 | return reconnectingReader, blobSize, nil |
| 1073 | } |
| 1074 | |
| 1075 | // getOCIDescriptorContents returns the contents a blob specified by descriptor in ref, which must fit within limit. |
| 1076 | func (c *dockerClient) getOCIDescriptorContents(ctx context.Context, ref dockerReference, desc imgspecv1.Descriptor, maxSize int, cache types.BlobInfoCache) ([]byte, error) { |
no test coverage detected