github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/pkg/image/distributionutil/blob.go (about)

     1  // Copyright © 2021 Alibaba Group Holding Ltd.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package distributionutil
    16  
    17  import (
    18  	"context"
    19  
    20  	"github.com/distribution/distribution/v3"
    21  	"github.com/opencontainers/go-digest"
    22  )
    23  
    24  type blobService struct {
    25  	descriptors map[digest.Digest]distribution.Descriptor
    26  }
    27  
    28  func (bs *blobService) Get(ctx context.Context, dgst digest.Digest) ([]byte, error) {
    29  	return []byte{}, nil
    30  }
    31  
    32  func (bs *blobService) Stat(ctx context.Context, dgst digest.Digest) (distribution.Descriptor, error) {
    33  	if descriptor, ok := bs.descriptors[dgst]; ok {
    34  		return descriptor, nil
    35  	}
    36  	return distribution.Descriptor{}, distribution.ErrBlobUnknown
    37  }
    38  
    39  func (bs *blobService) Open(ctx context.Context, dgst digest.Digest) (distribution.ReadSeekCloser, error) {
    40  	return nil, nil
    41  }
    42  
    43  func (bs *blobService) Put(ctx context.Context, mediaType string, p []byte) (distribution.Descriptor, error) {
    44  	d := distribution.Descriptor{
    45  		Digest:    digest.FromBytes(p),
    46  		Size:      int64(len(p)),
    47  		MediaType: mediaType,
    48  	}
    49  	bs.descriptors[d.Digest] = d
    50  	return d, nil
    51  }
    52  
    53  func (bs *blobService) Create(ctx context.Context, options ...distribution.BlobCreateOption) (distribution.BlobWriter, error) {
    54  	return nil, nil
    55  }
    56  
    57  func (bs *blobService) Resume(ctx context.Context, id string) (distribution.BlobWriter, error) {
    58  	return nil, nil
    59  }