initial commits

master
Charles Iliya Krempeaux 2022-11-13 20:49:36 -08:00
parent 9dcc5386e5
commit 5a9076dd18
1 changed files with 26 additions and 0 deletions

26
writerune.go 100644
View File

@ -0,0 +1,26 @@
package netln
import (
"github.com/reiver/go-utf8"
"fmt"
"io"
)
// writeRune deals with writing a single rune.
//
// It also makes sure that any error condition is represented as a Go error.
//
// It also wraps any errors, and provides a more appropriate error message.
func writeRune(writer io.Writer, r rune, expectedWritten int) error {
n, err := utf8.WriteRune(writer, r)
if nil != err {
return fmt.Errorf("problem writing UTF-8 character %U: %w", r, err)
}
if expectedWritten != n {
return fmt.Errorf("problem writing UTF-8 character %U — expected to write %d bytes, but actually wrote %b bytes", r, expectedWritten, n)
}
return nil
}