| 20 | } |
| 21 | |
| 22 | func CreateOutputFile(message string, fileName string) (err error) { |
| 23 | if _, err = os.Stat(fileName); err == nil { |
| 24 | err = fmt.Errorf(i18n.T("file_already_exists_not_overwriting"), fileName) |
| 25 | return |
| 26 | } |
| 27 | var file *os.File |
| 28 | if file, err = os.Create(fileName); err != nil { |
| 29 | err = fmt.Errorf(i18n.T("error_creating_file"), err) |
| 30 | return |
| 31 | } |
| 32 | defer file.Close() |
| 33 | if !strings.HasSuffix(message, "\n") { |
| 34 | message += "\n" |
| 35 | } |
| 36 | if _, err = file.WriteString(message); err != nil { |
| 37 | err = fmt.Errorf(i18n.T("error_writing_to_file"), err) |
| 38 | } else { |
| 39 | debuglog.Log("\n\n[Output also written to %s]\n", fileName) |
| 40 | } |
| 41 | return |
| 42 | } |
| 43 | |
| 44 | // CreateAudioOutputFile creates a binary file for audio data |
| 45 | func CreateAudioOutputFile(audioData []byte, fileName string) (err error) { |