ytva/file.go
2024-12-31 14:33:46 -07:00

23 lines
408 B
Go

package main
import (
"fmt"
"os"
"errors"
//"github.com/charmbracelet/log"
"github.com/h2non/filetype"
)
func getExtension(filePath string) (extension string, err error) {
buf, _ := os.ReadFile(filePath)
kind, _ := filetype.Match(buf)
if kind == filetype.Unknown {
return "", errors.New(fmt.Sprintf("Unknown file type."))
}
return kind.Extension, nil
}