The problem is that I am supposed to support writing a CSV response with text encoding both as UTF-8 and ISO8859-1
This does not seem to work as planned.
When I try to stream:
…
… encoding: rune not supported by encoding.
…
To set up the csv-writer I use the following code:
// w is http.ResponseWriter
var conv io.Writer = w
if encoding == altEncoding {
conv = charmap.ISO8859_1.NewEncoder().Writer(w)
}
csvWriter := csv.NewWriter(conv)
csvWriter.Comma = separator
Yes, that is awful truth about ISO8859-1 when converting from UTF-8 to ISO8859-1.
My data are names of persons and many of them are international, and as far as I am able to understand, those are the cause of this problem.
If its mostly names, you can try to ask the original data source for transcriptions or to create it computationally. But transcribing or dropping ISO8859-1 are probably the only options.
By using inconv on the terminal rather than a library wrapping it, you are just defering the problem. Unicode knows more than a million “characters”, ISO encodings can encode just 256. You’ll always have a loss of information when not using UTF-8/16/32.