2022-04-15 09:42:07 +02:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
ExtJPEG = ".jpg"
|
2023-02-11 20:18:04 +01:00
|
|
|
ExtPNG = ".png"
|
2022-10-07 16:37:47 +02:00
|
|
|
ExtDNG = ".dng"
|
|
|
|
ExtTHM = ".thm"
|
2022-04-15 09:42:07 +02:00
|
|
|
ExtAVC = ".avc"
|
2023-09-03 15:38:57 +02:00
|
|
|
ExtHEVC = ".hevc"
|
2023-02-22 20:58:21 +01:00
|
|
|
ExtMP4 = ".mp4"
|
2023-09-24 17:13:06 +02:00
|
|
|
ExtMOV = ".mov"
|
2023-09-03 15:38:57 +02:00
|
|
|
ExtYAML = ".yml"
|
2022-04-15 09:42:07 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Ext returns all extension of a file name including the dots.
|
|
|
|
func Ext(name string) string {
|
|
|
|
ext := filepath.Ext(name)
|
|
|
|
name = StripExt(name)
|
|
|
|
|
|
|
|
if Extensions.Known(name) {
|
|
|
|
ext = filepath.Ext(name) + ext
|
|
|
|
}
|
|
|
|
|
|
|
|
return ext
|
|
|
|
}
|
|
|
|
|
|
|
|
// NormalizedExt returns the file extension without dot and in lowercase.
|
|
|
|
func NormalizedExt(fileName string) string {
|
|
|
|
if dot := strings.LastIndex(fileName, "."); dot != -1 && len(fileName[dot+1:]) >= 1 {
|
|
|
|
return strings.ToLower(fileName[dot+1:])
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// LowerExt returns the file name extension with dot in lower case.
|
|
|
|
func LowerExt(fileName string) string {
|
|
|
|
if fileName == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.ToLower(filepath.Ext(fileName))
|
|
|
|
}
|
|
|
|
|
|
|
|
// TrimExt removes unwanted characters from file extension strings, and makes it lowercase for comparison.
|
|
|
|
func TrimExt(ext string) string {
|
|
|
|
return strings.ToLower(strings.Trim(ext, " .,;:“”'`\""))
|
|
|
|
}
|
|
|
|
|
|
|
|
// StripExt removes the file type extension from a file name (if any).
|
|
|
|
func StripExt(name string) string {
|
|
|
|
if end := strings.LastIndex(name, "."); end != -1 {
|
|
|
|
name = name[:end]
|
|
|
|
}
|
|
|
|
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
|
|
|
// StripKnownExt removes all known file type extension from a file name (if any).
|
|
|
|
func StripKnownExt(name string) string {
|
|
|
|
for Extensions.Known(name) {
|
|
|
|
name = StripExt(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
return name
|
|
|
|
}
|