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

Code before:
	// We expect this to be a limited list, so add an arbitrary limit (50).
	//
	// Note that DiffCompression is only using the last element, so perhaps we
	// should split on the last "+" only.
	suffixes = strings.SplitN(ext, "+", 50)
	sort.Strings(suffixes)
	return mediaType, suffixes
}

// IsNonDistributable returns true if the media type is non-distributable.
func IsNonDistributable(mt string) bool {
	return strings.HasPrefix(mt, "application/vnd.oci.image.layer.nondistributable.") ||
		strings.HasPrefix(mt, "application/vnd.docker.image.rootfs.foreign.")
}

// IsLayerType returns true if the media type is a layer
func IsLayerType(mt string) bool {
	if strings.HasPrefix(mt, "application/vnd.oci.image.layer.") {
		return true
	}

	// Parse Docker media types, strip off any + suffixes first
	switch base, _ := parseMediaTypes(mt); base {
	case MediaTypeDockerSchema2Layer, MediaTypeDockerSchema2LayerGzip,
		MediaTypeDockerSchema2LayerForeign, MediaTypeDockerSchema2LayerForeignGzip, MediaTypeDockerSchema2LayerZstd,
		MediaTypeErofsLayer:
		return true
	}
	return false
}

// IsDockerType returns true if the media type has "application/vnd.docker." prefix
func IsDockerType(mt string) bool {
	return strings.HasPrefix(mt, "application/vnd.docker.")
}

// IsManifestType returns true if the media type is an OCI-compatible manifest.
// No support for schema1 manifest.
func IsManifestType(mt string) bool {
	switch mt {
	case MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest:
		return true
	default:
		return false
	}
}

// IsIndexType returns true if the media type is an OCI-compatible index.
func IsIndexType(mt string) bool {
	switch mt {
	case ocispec.MediaTypeImageIndex, MediaTypeDockerSchema2ManifestList:

Review comment (performance):
Can we just add another case to explain this? like:
```go
    // Parse Docker media types, strip off any + suffixes first
	case MediaTypeDockerSchema2Layer, MediaTypeDockerSchema2LayerGzip,
		MediaTypeDockerSchema2LayerForeign, MediaTypeDockerSchema2LayerForeignGzip, MediaTypeDockerSchema2LayerZstd:
         return true
    // Allow EROFS native layers for efficient container image distribution.
    case MediaTypeErofsLayer:
         return true
```
So that https://github.com/containerd/containerd/pull/12506 is also benefited from this.


Code after:
	// We expect this to be a limited list, so add an arbitrary limit (50).
	//
	// Note that DiffCompression is only using the last element, so perhaps we
	// should split on the last "+" only.
	suffixes = strings.SplitN(ext, "+", 50)
	sort.Strings(suffixes)
	return mediaType, suffixes
}

// IsNonDistributable returns true if the media type is non-distributable.
func IsNonDistributable(mt string) bool {
	return strings.HasPrefix(mt, "application/vnd.oci.image.layer.nondistributable.") ||
		strings.HasPrefix(mt, "application/vnd.docker.image.rootfs.foreign.")
}

// IsLayerType returns true if the media type is a layer
func IsLayerType(mt string) bool {
	if strings.HasPrefix(mt, "application/vnd.oci.image.layer.") {
		return true
	}

	switch base, _ := parseMediaTypes(mt); base {
	// Parse Docker media types, strip off any + suffixes first
	case MediaTypeDockerSchema2Layer, MediaTypeDockerSchema2LayerGzip,
		MediaTypeDockerSchema2LayerForeign, MediaTypeDockerSchema2LayerForeignGzip, MediaTypeDockerSchema2LayerZstd:
		return true
	// Allow EROFS native layers for efficient container image distribution.
	case MediaTypeErofsLayer:
		return true
	}
	return false
}

// IsDockerType returns true if the media type has "application/vnd.docker." prefix
func IsDockerType(mt string) bool {
	return strings.HasPrefix(mt, "application/vnd.docker.")
}

// IsManifestType returns true if the media type is an OCI-compatible manifest.
// No support for schema1 manifest.
func IsManifestType(mt string) bool {
	switch mt {
	case MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest:
		return true
	default:
		return false
	}
}

// IsIndexType returns true if the media type is an OCI-compatible index.
func IsIndexType(mt string) bool {