func IsTextFile()

in pkg/preprocess/file.go [27:42]


func IsTextFile(path string) (bool, error) {
	if hasTextExtension(path) {
		return true, nil
	}
	f, err := os.Open(path)
	if err != nil {
		return false, errors.Wrap(err, "failed to open file")
	}
	defer f.Close()
	b := make([]byte, peekLen)
	_, err = f.Read(b)
	if err != nil && err != io.EOF {
		return false, errors.Wrap(err, "failed to read file")
	}
	return hasShebang(b), nil
}