added a few more useful readers

This commit is contained in:
Stephen McQuay 2016-06-02 23:16:06 -07:00
parent 8db9063571
commit e21b3e2452
No known key found for this signature in database
GPG Key ID: 1ABF428F71BAFC3D

View File

@ -7,25 +7,43 @@ import (
)
func init() {
Reader = &reader{}
Reader = &reader{0xca}
Zeros = &reader{0x00}
Fs = &reader{0xff}
HiLo = &reader{0xaa}
LoHi = &reader{0x55}
}
// Reader provides a steady stream of trash (non-random bytes) when read from
var Reader io.Reader
// Zeros provides a steady stream of 0x00
var Zeros io.Reader
// Fs provides a steady stream of 0xff
var Fs io.Reader
// HiLo provides a steady stream of 0xaa
var HiLo io.Reader
// LoHi provides a steady stream of 0x55
var LoHi io.Reader
// TimeoutReader returns a reader that returns io.EOF after dur.
func TimeoutReader(dur time.Duration) io.Reader {
return &timeoutReader{timeout: time.Now().Add(dur)}
}
type reader struct{}
type reader struct {
pattern byte
}
func (r *reader) Read(p []byte) (int, error) {
c := 0
var err error
for i := 0; i < len(p); i++ {
c++
p[i] = 0xca
p[i] = r.pattern
}
return c, err
}