Skip to content

Commit 2465672

Browse files
committed
added ReadAsUTF8(r io.Reader)
1 parent 366b72a commit 2465672

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

encoding.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@ package subtitles
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"strings"
88
"unicode/utf16"
99
"unicode/utf8"
1010
)
1111

12-
// ReadFileAsUTF8 reads text file, tries to convert to UTF8
13-
func ReadFileAsUTF8(fileName string) (string, error) {
12+
// ReadAsUTF8 tries to convert io.Reader to UTF8
13+
func ReadAsUTF8(r io.Reader) (string, error) {
1414

15-
data, err := ioutil.ReadFile(fileName)
15+
buf := new(bytes.Buffer)
16+
_, err := buf.ReadFrom(r)
1617
if err != nil {
17-
return "", err
18+
return "", nil
1819
}
1920

20-
utf8 := convertToUTF8(data)
21+
utf8 := convertToUTF8(buf.Bytes())
2122
return utf8, nil
2223
}
2324

0 commit comments

Comments
 (0)