From 115056cc203e3eba0868d6ceda12c767fe74e005 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Tue, 23 Jan 2024 06:08:11 -0800 Subject: [PATCH] initial commits --- writestring.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 writestring.go diff --git a/writestring.go b/writestring.go new file mode 100644 index 0000000..c378a96 --- /dev/null +++ b/writestring.go @@ -0,0 +1,21 @@ +package raft + +import ( + "io" + + "sourcecode.social/reiver/go-erorr" +) + +// writeString is similar to io.WriteString(), except that if the number of bytes written (by io.WriteString()) is not 'len(str)' then it returns an error. +func writeString(writer io.Writer, str string) error { + + n, err := io.WriteString(writer, str) + if nil != err { + return erorr.Errorf("problem writing string: %w", err) + } + if expected, actual := len(str), n ; expected != actual { + return erorr.Errorf("expected to write %d bytes but actually wrote %d bytes", expected, actual) + } + + return nil +}