Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read OPF file in utf-16 format #260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions epub/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@ type rootFile struct {
MediaType string `xml:"media-type,attr"`
}

func BypassReader(label string, input io.Reader) (io.Reader, error) {
return input, nil
}

// findRootFiles looks for the epub root files
func findRootFiles(r io.Reader) ([]rootFile, error) {
xd := xml.NewDecoder(r)
// deal with non utf-8 xml files
xd.CharsetReader = charset.NewReaderLabel
var roots []rootFile

nr, err := charset.NewReader(r, "utf-16")
if err != nil {
return nil, err
}
xd := xml.NewDecoder(nr)
xd.CharsetReader = BypassReader

for x, err := xd.Token(); x != nil && err == nil; x, err = xd.Token() {
if err != nil {
return nil, err
Expand Down