From a82d80cf7f1bcbb874352d405a05d0c58d71c103 Mon Sep 17 00:00:00 2001 From: kayomn Date: Tue, 20 Dec 2022 23:22:18 +0000 Subject: [PATCH] Fix build error --- ini.go | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/ini.go b/ini.go index 0875579..29f8d63 100644 --- a/ini.go +++ b/ini.go @@ -96,7 +96,7 @@ type Parser struct { } // Attempts to write `entries` to `writer`, returning any error that occured during writing. -func Write(writer io.Writer, entries []Entry) error { +func Write(writer io.StringWriter, entries []Entry) error { // TODO: Not happy with this solution to writing files, needs more revision. var section = "" @@ -104,16 +104,37 @@ func Write(writer io.Writer, entries []Entry) error { if entry.Section != section { section = entry.Section - writer.Write([]byte{'['}) - writer.Write([]byte(entry.Section)) - writer.Write([]byte{']', '\n'}) + if _, writeError := writer.WriteString("["); writeError != nil { + return writeError + } + + if _, writeError := writer.WriteString(entry.Section); writeError != nil { + return writeError + } + + if _, writeError := writer.WriteString("]"); writeError != nil { + return writeError + } } - writer.Write([]byte(entry.Key)) - writer.Write([]byte{' ', '=', ' '}) - writer.Write([]byte(entry.Value)) - writer.Write([]byte{'\n'}) + if _, writeError := writer.WriteString(entry.Key); writeError != nil { + return writeError + } + + if _, writeError := writer.WriteString(" = "); writeError != nil { + return writeError + } + + if _, writeError := writer.WriteString(entry.Value); writeError != nil { + return writeError + } + + if _, writeError := writer.WriteString("\n"); writeError != nil { + return writeError + } } + + return nil } // Returns a string with the the outer-most quotes surrounding `s` trimmed, should they exist.