initial commits

master
Charles Iliya Krempeaux 2024-01-23 06:06:22 -08:00
parent d20ea47b84
commit 9d67f90d74
1 changed files with 21 additions and 0 deletions

21
copyn.go 100644
View File

@ -0,0 +1,21 @@
package raft
import (
"io"
"sourcecode.social/reiver/go-erorr"
)
// copyN is similar to io.CopyN(), except that if the number of bytes written (by io.CopyN()) is not 'n' then it returns an error.
func copyN(writer io.Writer, reader io.Reader, n int64) error {
numWritten, err := io.CopyN(writer, reader, n)
if nil != err {
return erorr.Errorf("problem copying %d bytes from reader to writer: %w", n, err)
}
if expected, actual := n, numWritten ; expected != actual {
return erorr.Errorf("expected to write %d bytes but actually wrote %d bytes", expected, actual)
}
return nil
}