Skip to content

Commit

Permalink
added ReadAsUTF8(r io.Reader)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlindhe committed Jan 22, 2016
1 parent 366b72a commit 2465672
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ package subtitles
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"strings"
"unicode/utf16"
"unicode/utf8"
)

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

data, err := ioutil.ReadFile(fileName)
buf := new(bytes.Buffer)
_, err := buf.ReadFrom(r)
if err != nil {
return "", err
return "", nil
}

utf8 := convertToUTF8(data)
utf8 := convertToUTF8(buf.Bytes())
return utf8, nil
}

Expand Down

0 comments on commit 2465672

Please sign in to comment.