Files
go2tv/soapcalls/utils/subsgeneric.go
2024-12-20 23:16:48 +02:00

28 lines
413 B
Go

package utils
import (
"os"
"github.com/saintfish/chardet"
)
func getCharDet(path string) (string, error) {
f, err := os.Open(path)
if err != nil {
return "", err
}
defer f.Close()
firstBytes := make([]byte, 512)
n, err := f.Read(firstBytes)
if err != nil {
return "", err
}
det := chardet.NewTextDetector()
charGuess, err := det.DetectBest(firstBytes[:n])
return charGuess.Charset, err
}