@@ -18,7 +18,6 @@ package schema1
18
18
19
19
import (
20
20
"bytes"
21
- "compress/gzip"
22
21
"context"
23
22
"encoding/base64"
24
23
"encoding/json"
@@ -31,6 +30,7 @@ import (
31
30
32
31
"golang.org/x/sync/errgroup"
33
32
33
+ "github.com/containerd/containerd/archive/compression"
34
34
"github.com/containerd/containerd/content"
35
35
"github.com/containerd/containerd/errdefs"
36
36
"github.com/containerd/containerd/images"
@@ -255,8 +255,9 @@ func (c *Converter) fetchBlob(ctx context.Context, desc ocispec.Descriptor) erro
255
255
log .G (ctx ).Debug ("fetch blob" )
256
256
257
257
var (
258
- ref = remotes .MakeRefKey (ctx , desc )
259
- calc = newBlobStateCalculator ()
258
+ ref = remotes .MakeRefKey (ctx , desc )
259
+ calc = newBlobStateCalculator ()
260
+ compressMethod = compression .Gzip
260
261
)
261
262
262
263
// size may be unknown, set to zero for content ingest
@@ -280,13 +281,14 @@ func (c *Converter) fetchBlob(ctx context.Context, desc ocispec.Descriptor) erro
280
281
}
281
282
defer ra .Close ()
282
283
283
- gr , err := gzip . NewReader (content .NewReader (ra ))
284
+ r , err := compression . DecompressStream (content .NewReader (ra ))
284
285
if err != nil {
285
286
return err
286
287
}
287
- defer gr .Close ()
288
288
289
- _ , err = io .Copy (calc , gr )
289
+ compressMethod = r .GetCompression ()
290
+ _ , err = io .Copy (calc , r )
291
+ r .Close ()
290
292
if err != nil {
291
293
return err
292
294
}
@@ -303,13 +305,14 @@ func (c *Converter) fetchBlob(ctx context.Context, desc ocispec.Descriptor) erro
303
305
pr , pw := io .Pipe ()
304
306
305
307
eg .Go (func () error {
306
- gr , err := gzip . NewReader (pr )
308
+ r , err := compression . DecompressStream (pr )
307
309
if err != nil {
308
310
return err
309
311
}
310
- defer gr .Close ()
311
312
312
- _ , err = io .Copy (calc , gr )
313
+ compressMethod = r .GetCompression ()
314
+ _ , err = io .Copy (calc , r )
315
+ r .Close ()
313
316
pr .CloseWithError (err )
314
317
return err
315
318
})
@@ -333,6 +336,11 @@ func (c *Converter) fetchBlob(ctx context.Context, desc ocispec.Descriptor) erro
333
336
desc .Size = info .Size
334
337
}
335
338
339
+ if compressMethod == compression .Uncompressed {
340
+ log .G (ctx ).WithField ("id" , desc .Digest ).Debugf ("changed media type for uncompressed schema1 layer blob" )
341
+ desc .MediaType = images .MediaTypeDockerSchema2Layer
342
+ }
343
+
336
344
state := calc .State ()
337
345
338
346
c .mu .Lock ()
@@ -342,6 +350,7 @@ func (c *Converter) fetchBlob(ctx context.Context, desc ocispec.Descriptor) erro
342
350
343
351
return nil
344
352
}
353
+
345
354
func (c * Converter ) schema1ManifestHistory () ([]ocispec.History , []digest.Digest , error ) {
346
355
if c .pulledManifest == nil {
347
356
return nil , nil , errors .New ("missing schema 1 manifest for conversion" )
0 commit comments