peridot/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/utilities/readerfactory.go

20 lines
386 B
Go
Raw Normal View History

2022-07-07 20:11:50 +00:00
package utilities
import (
"bytes"
"io"
)
// IOReaderFactory takes in an io.Reader and returns a function that will allow you to create a new reader that begins
// at the start of the stream
func IOReaderFactory(r io.Reader) (func() io.Reader, error) {
b, err := io.ReadAll(r)
2022-07-07 20:11:50 +00:00
if err != nil {
return nil, err
}
return func() io.Reader {
return bytes.NewReader(b)
}, nil
}