ytva/file.go

24 lines
408 B
Go
Raw Normal View History

2024-12-31 16:33:46 -05:00
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
}