init
This commit is contained in:
24
internal/ioutilx/byte.go
Executable file
24
internal/ioutilx/byte.go
Executable 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
17
internal/ioutilx/zero.go
Executable 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
|
||||
}
|
Reference in New Issue
Block a user