github.com/onsi/gomega@v1.32.0/internal/gutil/post_ioutil.go (about) 1 //go:build go1.16 2 // +build go1.16 3 4 // Package gutil is a replacement for ioutil, which should not be used in new 5 // code as of Go 1.16. With Go 1.16 and higher, this implementation 6 // uses the ioutil replacement functions in "io" and "os" with some 7 // Gomega specifics. This means that we should not get deprecation warnings 8 // for ioutil when they are added. 9 package gutil 10 11 import ( 12 "io" 13 "os" 14 ) 15 16 func NopCloser(r io.Reader) io.ReadCloser { 17 return io.NopCloser(r) 18 } 19 20 func ReadAll(r io.Reader) ([]byte, error) { 21 return io.ReadAll(r) 22 } 23 24 func ReadDir(dirname string) ([]string, error) { 25 entries, err := os.ReadDir(dirname) 26 if err != nil { 27 return nil, err 28 } 29 30 var names []string 31 for _, entry := range entries { 32 names = append(names, entry.Name()) 33 } 34 35 return names, nil 36 } 37 38 func ReadFile(filename string) ([]byte, error) { 39 return os.ReadFile(filename) 40 } 41 42 func MkdirTemp(dir, pattern string) (string, error) { 43 return os.MkdirTemp(dir, pattern) 44 } 45 46 func WriteFile(filename string, data []byte) error { 47 return os.WriteFile(filename, data, 0644) 48 }