readerfactory.go 403 B

1234567891011121314151617181920
  1. package utilities
  2. import (
  3. "bytes"
  4. "io"
  5. "io/ioutil"
  6. )
  7. // IOReaderFactory takes in an io.Reader and returns a function that will allow you to create a new reader that begins
  8. // at the start of the stream
  9. func IOReaderFactory(r io.Reader) (func() io.Reader, error) {
  10. b, err := ioutil.ReadAll(r)
  11. if err != nil {
  12. return nil, err
  13. }
  14. return func() io.Reader {
  15. return bytes.NewReader(b)
  16. }, nil
  17. }