@@ -18,7 +18,6 @@ package distribution
1818
1919import (
2020 "context"
21- "crypto/sha256"
2221 "fmt"
2322 "io"
2423 "regexp"
@@ -28,6 +27,7 @@ import (
2827 "github.com/distribution/distribution/v3/registry/storage/driver"
2928 "github.com/distribution/distribution/v3/registry/storage/driver/filesystem"
3029 ref "github.com/distribution/reference"
30+ sha256 "github.com/minio/sha256-simd"
3131 godigest "github.com/opencontainers/go-digest"
3232 ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3333)
@@ -172,30 +172,35 @@ func (s *storage) PullBlob(ctx context.Context, repo, digest string) (io.ReadClo
172172}
173173
174174// PushBlob pushes the blob to the storage.
175- func (s * storage ) PushBlob (ctx context.Context , repo string , blobReader io.Reader ) (string , int64 , error ) {
175+ func (s * storage ) PushBlob (ctx context.Context , repo string , blobReader io.Reader , provisional ocispec. Descriptor ) (string , int64 , error ) {
176176 repository , err := s .repository (ctx , repo )
177177 if err != nil {
178178 return "" , 0 , err
179179 }
180180
181- // use teeReader to calculate the digest.
182181 hash := sha256 .New ()
183- teeReader := io .TeeReader (blobReader , hash )
182+ if provisional .Digest == "" {
183+ blobReader = io .TeeReader (blobReader , hash )
184+ }
184185
185186 blob , err := repository .Blobs (ctx ).Create (ctx )
186187 if err != nil {
187188 return "" , 0 , err
188189 }
189190
190- size , err := blob .ReadFrom (teeReader )
191+ size , err := blob .ReadFrom (blobReader )
191192 if err != nil {
192193 return "" , 0 , err
193194 }
194195
195- desc , err := blob .Commit (ctx , ocispec.Descriptor {
196- Digest : godigest .Digest (fmt .Sprintf ("sha256:%x" , hash .Sum (nil ))),
197- Size : size ,
198- })
196+ // if the provided provisional descriptor is not empty, we can just use it to commit,
197+ // otherwise we need to calculate the digest.
198+ if provisional .Digest == "" {
199+ provisional .Digest = godigest .Digest (fmt .Sprintf ("sha256:%x" , hash .Sum (nil )))
200+ provisional .Size = size
201+ }
202+
203+ desc , err := blob .Commit (ctx , provisional )
199204 if err != nil {
200205 return "" , 0 , nil
201206 }
0 commit comments