7 "golang.org/x/text/encoding/ianaindex"
10// DecodeReader returns a reader that reads from r, decoding as charset. If
11// charset is empty, us-ascii, utf-8 or unknown, the original reader is
12// returned and no decoding takes place.
13func DecodeReader(charset string, r io.Reader) io.Reader {
14 switch strings.ToLower(charset) {
15 case "", "us-ascii", "utf-8":
18 enc, _ := ianaindex.MIME.Encoding(charset)
20 enc, _ = ianaindex.IANA.Encoding(charset)
22 // todo: ianaindex doesn't know all encodings, e.g. gb2312. should we transform them, with which code?
26 return enc.NewDecoder().Reader(r)