added random reader
I thought this one might be slow but it gets 400Mb/s on my mac.
This commit is contained in:
parent
e58f07775c
commit
8bd4b0a0b1
@ -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)
|
||||
|
4
trash.go
4
trash.go
@ -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)}
|
||||
|
Loading…
Reference in New Issue
Block a user