prow/pod-utils/gcs/metadata.go
func MetadataFromFileName(filename string) (string, map[string]string) {
	metadata := make(map[string]string)
	segments := strings.Split(filename, ".")
	index := len(segments) - 1
	segment := segments[index]

	// https://www.iana.org/assignments/http-parameters/http-parameters.xhtml#content-coding
	switch segment {
	case "gz", "gzip":
		metadata["Content-Encoding"] = "gzip"
	}

	if _, ok := metadata["Content-Encoding"]; ok {
		if index == 0 {
			segment = ""
		} else {
			filename = filename[:len(filename)-len(segment)-1]
			index -= 1
			segment = segments[index]
		}
	}

	if segment != "" {
		mediaType := mime.TypeByExtension("." + segment)
		if mediaType != "" {
			metadata["Content-Type"] = mediaType
		}
	}

	if _, ok := metadata["Content-Type"]; !ok {
		if _, ok := metadata["Content-Encoding"]; ok {
			metadata["Content-Type"] = "application/gzip"
			delete(metadata, "Content-Encoding")
		}
	}

	return filename, metadata
}
func MetadataFromFileName(filename string) (string, map[string]string) {
	metadata := make(map[string]string)
	segments := strings.Split(filename, ".")
	index := len(segments) - 1
	segment := segments[index]

	// https://www.iana.org/assignments/http-parameters/http-parameters.xhtml#content-coding
	switch segment {
	case "gz", "gzip":
		metadata["Content-Encoding"] = "gzip"
	}

	if _, ok := metadata["Content-Encoding"]; ok {
		if index == 0 {
			segment = ""
		} else {
			filename = filename[:len(filename)-len(segment)-1]
			index -= 1
			segment = segments[index]
		}
	}

	if segment != "" {
		mediaType := mime.TypeByExtension("." + segment)
		if mediaType != "" {
			metadata["Content-Type"] = mediaType
		}
	}

	if _, ok := metadata["Content-Type"]; !ok {
		if _, ok := metadata["Content-Encoding"]; ok {
			metadata["Content-Type"] = "application/gzip"
			delete(metadata, "Content-Encoding")
		}
	}

	return filename, metadata
}
// MetadataFromFileName guesses file metadata from the filename and a
// simplifed filename.  For example, build-log.txt.gz would be:
//
//   Content-Type: text/plain; charset=utf-8
//   Content-Encoding: gzip
//
// and the simplified filename would be build-log.txt (excluding the
// content encoding extension).