gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

read.go (654B)


      1 package iotools
      2 
      3 import (
      4 	"io"
      5 )
      6 
      7 // ReaderFunc is a function signature which allows
      8 // a function to implement the io.Reader type.
      9 type ReaderFunc func([]byte) (int, error)
     10 
     11 func (r ReaderFunc) Read(b []byte) (int, error) {
     12 	return r(b)
     13 }
     14 
     15 // ReadCloser wraps an io.Reader and io.Closer in order to implement io.ReadCloser.
     16 func ReadCloser(r io.Reader, c io.Closer) io.ReadCloser {
     17 	return &struct {
     18 		io.Reader
     19 		io.Closer
     20 	}{r, c}
     21 }
     22 
     23 // NopReadCloser wraps an io.Reader to implement io.ReadCloser with empty io.Closer implementation.
     24 func NopReadCloser(r io.Reader) io.ReadCloser {
     25 	return ReadCloser(r, CloserFunc(func() error {
     26 		return nil
     27 	}))
     28 }