setEncoding recreates the reader with the specified encoding.
(encoding string)
| 162 | |
| 163 | // setEncoding recreates the reader with the specified encoding. |
| 164 | func (d *Decoder) setEncoding(encoding string) bool { |
| 165 | // Recreate the reader with the specified encoding. |
| 166 | // We are going to wrap bufio.Reader with bufio.Reader again, |
| 167 | // but non-UTF-8 encodings are rare, so this should be fine. |
| 168 | newr, err := charset.NewReaderLabel(encoding, d.r) |
| 169 | if err != nil { |
| 170 | d.err = fmt.Errorf("can't create reader for encoding %q: %w", encoding, err) |
| 171 | return false |
| 172 | } |
| 173 | |
| 174 | d.setReader(newr) |
| 175 | |
| 176 | return true |
| 177 | } |
| 178 | |
| 179 | // checkBOM checks for a Byte Order Mark (BOM) at the start of the stream |
| 180 | // and adjusts the reader accordingly. |
no test coverage detected