sm
/
trash
1
0
Fork 0

added random reader

I thought this one might be slow but it gets 400Mb/s on my mac.
This commit is contained in:
Stephen McQuay 2017-12-27 22:31:28 -08:00
parent e58f07775c
commit 8bd4b0a0b1
Signed by: sm
GPG Key ID: 4E4B72F479BA3CE5
2 changed files with 6 additions and 0 deletions

View File

@ -25,6 +25,8 @@ func main() {
r = trash.HiLo
case "lohi", "55", "5":
r = trash.LoHi
case "rand", "random":
r = trash.Random
default:
fmt.Fprintf(os.Stderr, "unsupported algorithm: %v\ntry one of 'lo(w)', 'hi(gh)', 'hilo', 'lohi', 'trash'\n", *algo)
os.Exit(1)

View File

@ -3,6 +3,7 @@ package trash
import (
"io"
"math/rand"
"time"
)
@ -12,6 +13,7 @@ func init() {
Fs = &reader{0xff}
HiLo = &reader{0xaa}
LoHi = &reader{0x55}
Random = rand.New(rand.NewSource(time.Now().UnixNano()))
}
// Reader provides a steady stream of trash (non-random bytes) when read from
@ -29,6 +31,8 @@ var HiLo io.Reader
// LoHi provides a steady stream of 0x55
var LoHi io.Reader
var Random 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)}