Repository: containerd/containerd
File: core/images/mediatypes.go (Go)

Code before:
	MediaTypeDockerSchema2Manifest         = "application/vnd.docker.distribution.manifest.v2+json"
	MediaTypeDockerSchema2ManifestList     = "application/vnd.docker.distribution.manifest.list.v2+json"

	// Checkpoint/Restore Media Types

	MediaTypeContainerd1Checkpoint               = "application/vnd.containerd.container.criu.checkpoint.criu.tar"
	MediaTypeContainerd1CheckpointPreDump        = "application/vnd.containerd.container.criu.checkpoint.predump.tar"
	MediaTypeContainerd1Resource                 = "application/vnd.containerd.container.resource.tar"
	MediaTypeContainerd1RW                       = "application/vnd.containerd.container.rw.tar"
	MediaTypeContainerd1CheckpointConfig         = "application/vnd.containerd.container.checkpoint.config.v1+proto"
	MediaTypeContainerd1CheckpointOptions        = "application/vnd.containerd.container.checkpoint.options.v1+proto"
	MediaTypeContainerd1CheckpointRuntimeName    = "application/vnd.containerd.container.checkpoint.runtime.name"
	MediaTypeContainerd1CheckpointRuntimeOptions = "application/vnd.containerd.container.checkpoint.runtime.options+proto"

	// MediaTypeDockerSchema1Manifest is the legacy Docker schema1 manifest
	MediaTypeDockerSchema1Manifest = "application/vnd.docker.distribution.manifest.v1+prettyjws"

	// Encrypted media types

	MediaTypeImageLayerEncrypted     = ocispec.MediaTypeImageLayer + "+encrypted"
	MediaTypeImageLayerGzipEncrypted = ocispec.MediaTypeImageLayerGzip + "+encrypted"

	// EROFS media type.
	// The ".erofs" suffix is kept for compatibility with containerd 2.1,
	// which detect native EROFS layers by checking whether the media type ends with ".erofs".
	MediaTypeErofsLayer = "vnd.erofs.layer.overlayfs.v1.erofs"

	// In-toto attestation
	MediaTypeInToto = "application/vnd.in-toto+json"
)

// DiffCompression returns the compression as defined by the layer diff media
// type. For Docker media types without compression, "unknown" is returned to
// indicate that the media type may be compressed. If the media type is not
// recognized as a layer diff, then it returns errdefs.ErrNotImplemented
func DiffCompression(ctx context.Context, mediaType string) (string, error) {
	base, ext := parseMediaTypes(mediaType)
	switch base {
	case MediaTypeDockerSchema2Layer, MediaTypeDockerSchema2LayerForeign:
		if len(ext) > 0 {
			// Type is wrapped
			return "", nil
		}
		// These media types may have been compressed but failed to
		// use the correct media type. The decompression function
		// should detect and handle this case.
		return "unknown", nil
	case MediaTypeDockerSchema2LayerGzip, MediaTypeDockerSchema2LayerForeignGzip:
		if len(ext) > 0 {
			// Type is wrapped
			return "", nil

Review comment (suggestion):
Can you help me understand the reasoning behind two choices here?

1) is there a reason this mediaType string starts at `vnd` instead of `application/vnd` like the others?
2) what's the purpose of including `overlayfs` as part of the subtype? I've seen strings that use `layer.v1` but didn't find any precedent for `layer.{something}.v1` (other than `nondistributable`). My guess is it's to signal that erofs is an overlay filesystem, but it's not clear to me why its important to include that in the media type.

Code after:
	MediaTypeDockerSchema2Manifest         = "application/vnd.docker.distribution.manifest.v2+json"
	MediaTypeDockerSchema2ManifestList     = "application/vnd.docker.distribution.manifest.list.v2+json"

	// Checkpoint/Restore Media Types

	MediaTypeContainerd1Checkpoint               = "application/vnd.containerd.container.criu.checkpoint.criu.tar"
	MediaTypeContainerd1CheckpointPreDump        = "application/vnd.containerd.container.criu.checkpoint.predump.tar"
	MediaTypeContainerd1Resource                 = "application/vnd.containerd.container.resource.tar"
	MediaTypeContainerd1RW                       = "application/vnd.containerd.container.rw.tar"
	MediaTypeContainerd1CheckpointConfig         = "application/vnd.containerd.container.checkpoint.config.v1+proto"
	MediaTypeContainerd1CheckpointOptions        = "application/vnd.containerd.container.checkpoint.options.v1+proto"
	MediaTypeContainerd1CheckpointRuntimeName    = "application/vnd.containerd.container.checkpoint.runtime.name"
	MediaTypeContainerd1CheckpointRuntimeOptions = "application/vnd.containerd.container.checkpoint.runtime.options+proto"

	// MediaTypeDockerSchema1Manifest is the legacy Docker schema1 manifest
	MediaTypeDockerSchema1Manifest = "application/vnd.docker.distribution.manifest.v1+prettyjws"

	// Encrypted media types

	MediaTypeImageLayerEncrypted     = ocispec.MediaTypeImageLayer + "+encrypted"
	MediaTypeImageLayerGzipEncrypted = ocispec.MediaTypeImageLayerGzip + "+encrypted"

	// EROFS media type
	MediaTypeErofsLayer = "application/vnd.erofs.layer.v1"

	// In-toto attestation
	MediaTypeInToto = "application/vnd.in-toto+json"
)

// DiffCompression returns the compression as defined by the layer diff media
// type. For Docker media types without compression, "unknown" is returned to
// indicate that the media type may be compressed. If the media type is not
// recognized as a layer diff, then it returns errdefs.ErrNotImplemented
func DiffCompression(ctx context.Context, mediaType string) (string, error) {
	base, ext := parseMediaTypes(mediaType)
	switch base {
	case MediaTypeDockerSchema2Layer, MediaTypeDockerSchema2LayerForeign:
		if len(ext) > 0 {
			// Type is wrapped
			return "", nil
		}
		// These media types may have been compressed but failed to
		// use the correct media type. The decompression function
		// should detect and handle this case.
		return "unknown", nil
	case MediaTypeDockerSchema2LayerGzip, MediaTypeDockerSchema2LayerForeignGzip:
		if len(ext) > 0 {
			// Type is wrapped
			return "", nil
		}
		return "gzip", nil