MCPcopy Create free account
hub / github.com/containers/image / getBlob

Method getBlob

docker/docker_client.go:1037–1073  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
1037func (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.
1076func (c *dockerClient) getOCIDescriptorContents(ctx context.Context, ref dockerReference, desc imgspecv1.Descriptor, maxSize int, cache types.BlobInfoCache) ([]byte, error) {

Callers 2

GetBlobMethod · 0.80

Calls 12

getExternalBlobMethod · 0.95
makeRequestMethod · 0.95
PathFunction · 0.92
bicTransportScopeFunction · 0.85
newBICLocationReferenceFunction · 0.85
newBodyReaderFunction · 0.85
getBlobSizeFunction · 0.70
StringMethod · 0.65
CloseMethod · 0.65
RecordKnownLocationMethod · 0.65
TransportMethod · 0.65

Tested by

no test coverage detected