Skip to content

Commit

Permalink
fix iso-8859-1 (#106)
Browse files Browse the repository at this point in the history
fixes issue where uniref files couldn't be parsed because they are encoded in iso-8859-1, not utf-8.
  • Loading branch information
Koeng101 authored Dec 14, 2024
1 parent 1e2a946 commit 486fdda
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/bio/uniprot/uniprot.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"io"
"net/http"
"net/url"
"strings"
)

// Decoder decodes XML elements2
Expand Down Expand Up @@ -67,6 +68,14 @@ type Parser struct {

func NewParser(r io.Reader) *Parser {
decoder := xml.NewDecoder(r)
// Oddly enough, the uniref datasets use iso-8859-1, not UTF-8. So we need
// to incorporate this decoder charset reader.
decoder.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) {
if strings.ToLower(charset) == "iso-8859-1" {
return input, nil // ISO-8859-1 bytes can be read directly as UTF-8
}
return nil, fmt.Errorf("unsupported charset: %s", charset)
}
return &Parser{decoder: decoder}
}

Expand Down

0 comments on commit 486fdda

Please sign in to comment.