This commit is contained in:
2025-04-19 22:56:37 +08:00
commit ceca244eaf
50 changed files with 7321 additions and 0 deletions

24
internal/ioutilx/byte.go Executable file
View File

@@ -0,0 +1,24 @@
// Package ioutilx implements extended input/output utility functions.
package ioutilx
import (
"io"
)
// ReadByte reads and returns the next byte from r.
func ReadByte(r io.Reader) (byte, error) {
var buf [1]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return 0, err
}
return buf[0], nil
}
// WriteByte writes the given byte to w.
func WriteByte(w io.Writer, b byte) error {
buf := [1]byte{b}
if _, err := w.Write(buf[:]); err != nil {
return err
}
return nil
}

17
internal/ioutilx/zero.go Executable file
View File

@@ -0,0 +1,17 @@
package ioutilx
// Zero is an io.Reader which always reads zero bytes.
var Zero zero
// zero is an io.Reader which always reads zero bytes.
type zero struct {
}
// Read reads len(b) zero bytes into b. It returns the number of bytes read and
// a nil error value.
func (zero) Read(b []byte) (n int, err error) {
for i := range b {
b[i] = 0
}
return len(b), nil
}