@@ -185,7 +185,10 @@ func openTmpFileNoTmpFile(tmpDir string) (*os.File, error) {
185
185
// Returns (manifest blob, parsed manifest, tar-split file or nil, manifest offset).
186
186
// The opened tar-split file’s position is unspecified.
187
187
// It may return an error matching ErrFallbackToOrdinaryLayerDownload / errFallbackCanConvert.
188
- func readZstdChunkedManifest (tmpDir string , blobStream ImageSourceSeekable , tocDigest digest.Digest , annotations map [string ]string ) (_ []byte , _ * minimal.TOC , _ * os.File , _ int64 , retErr error ) {
188
+ // The compressed parameter indicates whether the manifest and tar-split data are zstd-compressed
189
+ // (true) or stored uncompressed (false). Uncompressed data is used only for an optimization to convert
190
+ // a regular OCI layer to zstd:chunked when convert_images is set, and it is not used for distributed images.
191
+ func readZstdChunkedManifest (tmpDir string , blobStream ImageSourceSeekable , tocDigest digest.Digest , annotations map [string ]string , compressed bool ) (_ []byte , _ * minimal.TOC , _ * os.File , _ int64 , retErr error ) {
189
192
offsetMetadata := annotations [minimal .ManifestInfoKey ]
190
193
if offsetMetadata == "" {
191
194
return nil , nil , nil , 0 , fmt .Errorf ("%q annotation missing" , minimal .ManifestInfoKey )
@@ -261,7 +264,7 @@ func readZstdChunkedManifest(tmpDir string, blobStream ImageSourceSeekable, tocD
261
264
return nil , nil , nil , 0 , err
262
265
}
263
266
264
- decodedBlob , err := decodeAndValidateBlob (manifest , manifestLengthUncompressed , tocDigest .String ())
267
+ decodedBlob , err := decodeAndValidateBlob (manifest , manifestLengthUncompressed , tocDigest .String (), compressed )
265
268
if err != nil {
266
269
return nil , nil , nil , 0 , fmt .Errorf ("validating and decompressing TOC: %w" , err )
267
270
}
@@ -288,7 +291,7 @@ func readZstdChunkedManifest(tmpDir string, blobStream ImageSourceSeekable, tocD
288
291
decodedTarSplit .Close ()
289
292
}
290
293
}()
291
- if err := decodeAndValidateBlobToStream (tarSplit , decodedTarSplit , toc .TarSplitDigest .String ()); err != nil {
294
+ if err := decodeAndValidateBlobToStream (tarSplit , decodedTarSplit , toc .TarSplitDigest .String (), compressed ); err != nil {
292
295
return nil , nil , nil , 0 , fmt .Errorf ("validating and decompressing tar-split: %w" , err )
293
296
}
294
297
// We use the TOC for creating on-disk files, but the tar-split for creating metadata
@@ -487,11 +490,15 @@ func validateBlob(blob []byte, expectedCompressedChecksum string) error {
487
490
return nil
488
491
}
489
492
490
- func decodeAndValidateBlob (blob []byte , lengthUncompressed uint64 , expectedCompressedChecksum string ) ([]byte , error ) {
493
+ func decodeAndValidateBlob (blob []byte , lengthUncompressed uint64 , expectedCompressedChecksum string , compressed bool ) ([]byte , error ) {
491
494
if err := validateBlob (blob , expectedCompressedChecksum ); err != nil {
492
495
return nil , err
493
496
}
494
497
498
+ if ! compressed {
499
+ return blob , nil
500
+ }
501
+
495
502
decoder , err := zstd .NewReader (nil )
496
503
if err != nil {
497
504
return nil , err
@@ -502,11 +509,16 @@ func decodeAndValidateBlob(blob []byte, lengthUncompressed uint64, expectedCompr
502
509
return decoder .DecodeAll (blob , b )
503
510
}
504
511
505
- func decodeAndValidateBlobToStream (blob []byte , w * os.File , expectedCompressedChecksum string ) error {
512
+ func decodeAndValidateBlobToStream (blob []byte , w * os.File , expectedCompressedChecksum string , compressed bool ) error {
506
513
if err := validateBlob (blob , expectedCompressedChecksum ); err != nil {
507
514
return err
508
515
}
509
516
517
+ if ! compressed {
518
+ _ , err := w .Write (blob )
519
+ return err
520
+ }
521
+
510
522
decoder , err := zstd .NewReader (bytes .NewReader (blob ))
511
523
if err != nil {
512
524
return err
0 commit comments