We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 366b72a commit 2465672Copy full SHA for 2465672
encoding.go
@@ -3,21 +3,22 @@ package subtitles
3
import (
4
"bytes"
5
"fmt"
6
- "io/ioutil"
+ "io"
7
"strings"
8
"unicode/utf16"
9
"unicode/utf8"
10
)
11
12
-// ReadFileAsUTF8 reads text file, tries to convert to UTF8
13
-func ReadFileAsUTF8(fileName string) (string, error) {
+// ReadAsUTF8 tries to convert io.Reader to UTF8
+func ReadAsUTF8(r io.Reader) (string, error) {
14
15
- data, err := ioutil.ReadFile(fileName)
+ buf := new(bytes.Buffer)
16
+ _, err := buf.ReadFrom(r)
17
if err != nil {
- return "", err
18
+ return "", nil
19
}
20
- utf8 := convertToUTF8(data)
21
+ utf8 := convertToUTF8(buf.Bytes())
22
return utf8, nil
23
24
0 commit comments