diff options
Diffstat (limited to 'src/crypto/rand/rand.go')
-rw-r--r-- | src/crypto/rand/rand.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/crypto/rand/rand.go b/src/crypto/rand/rand.go index fddd1147e6..f2c276008d 100644 --- a/src/crypto/rand/rand.go +++ b/src/crypto/rand/rand.go @@ -23,3 +23,21 @@ var Reader io.Reader func Read(b []byte) (n int, err error) { return io.ReadFull(Reader, b) } + +// batched returns a function that calls f to populate a []byte by chunking it +// into subslices of, at most, readMax bytes. +func batched(f func([]byte) error, readMax int) func([]byte) error { + return func(out []byte) error { + for len(out) > 0 { + read := len(out) + if read > readMax { + read = readMax + } + if err := f(out[:read]); err != nil { + return err + } + out = out[read:] + } + return nil + } +} |