summaryrefslogtreecommitdiff
path: root/encoding.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2022-01-23 23:52:53 +0100
committerRené 'Necoro' Neumann <necoro@necoro.eu>2022-01-23 23:52:53 +0100
commitcc27626d016f8e13cfc86291ae9ddfc1a6e9d09a (patch)
tree044777f6359dcfc01d82a52521ae34b866651f97 /encoding.go
parent27791043e7e07ba33ffde6d180fcad9bfa992921 (diff)
downloadengarde-importer-cc27626d016f8e13cfc86291ae9ddfc1a6e9d09a.tar.gz
engarde-importer-cc27626d016f8e13cfc86291ae9ddfc1a6e9d09a.tar.bz2
engarde-importer-cc27626d016f8e13cfc86291ae9ddfc1a6e9d09a.zip
Factor out `encodedWriter`
Diffstat (limited to 'encoding.go')
-rw-r--r--encoding.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/encoding.go b/encoding.go
index d77cd65..b7511c5 100644
--- a/encoding.go
+++ b/encoding.go
@@ -5,12 +5,13 @@ import (
"io"
"github.com/gogs/chardet"
+ "golang.org/x/text/encoding/charmap"
"golang.org/x/text/encoding/ianaindex"
)
-// getEncodedReader tries to determine the encoding of the content of `r`.
+// encodedReader tries to determine the encoding of the content of `r`.
// It returns a new reader that returns UTF-8 content.
-func getEncodedReader(r io.Reader) (io.Reader, error) {
+func encodedReader(r io.Reader) (io.Reader, error) {
buf := make([]byte, 128)
n, err := io.ReadFull(r, buf)
@@ -38,3 +39,8 @@ func getEncodedReader(r io.Reader) (io.Reader, error) {
return enc.NewDecoder().Reader(r), nil
}
+
+// encodedWriter returns a wrapper around the passed in writer that encodes into the expected charset.
+func encodedWriter(w io.Writer) io.Writer {
+ return charmap.ISO8859_1.NewEncoder().Writer(w)
+}