github.com/searKing/golang/go@v1.2.117/io/ioutil/ioutil.go (about) 1 // Copyright 2022 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package ioutil 6 7 import ( 8 "io" 9 "os" 10 11 os_ "github.com/searKing/golang/go/os" 12 ) 13 14 // WriteAll writes data to a file named by filename. 15 // If the file does not exist, WriteAll creates it with mode 0666 (before umask) 16 // If the dir does not exist, WriteAll creates it with 0755 (before umask) 17 // otherwise WriteAll truncates it before writing, without changing permissions. 18 // 19 // As of Go 1.16, this function simply calls os.WriteAll. 20 func WriteAll(filename string, data []byte) error { 21 return os_.WriteAll(filename, data) 22 } 23 24 // WriteFileAll is the generalized open call; most users will use WriteAll instead. 25 // It writes data to a file named by filename. 26 // If the file does not exist, WriteFileAll creates it with permissions fileperm (before umask) 27 // If the dir does not exist, WriteFileAll creates it with permissions dirperm (before umask) 28 // otherwise WriteFileAll truncates it before writing, without changing permissions. 29 // 30 // As of Go 1.16, this function simply calls os.WriteFileAll. 31 func WriteFileAll(filename string, data []byte, dirperm, fileperm os.FileMode) error { 32 return os_.WriteFileAll(filename, data, dirperm, fileperm) 33 } 34 35 // WriteAllFrom writes data to a file named by filename from r until EOF or error. 36 // If the file does not exist, WriteAll creates it with mode 0666 (before umask) 37 // If the dir does not exist, WriteAll creates it with 0755 (before umask) 38 // otherwise WriteAll truncates it before writing, without changing permissions. 39 // 40 // As of Go 1.16, this function simply calls os.WriteAllFrom. 41 func WriteAllFrom(filename string, r io.Reader) error { 42 return os_.WriteAllFrom(filename, r) 43 } 44 45 // WriteFileAllFrom is the generalized open call; most users will use WriteAllFrom instead. 46 // It writes data to a file named by filename from r until EOF or error. 47 // If the file does not exist, WriteFileAllFrom creates it with permissions fileperm (before umask) 48 // If the dir does not exist, WriteFileAllFrom creates it with permissions dirperm (before umask) 49 // otherwise WriteFileAllFrom truncates it before writing, without changing permissions. 50 // 51 // As of Go 1.16, this function simply calls os.WriteFileAllFrom. 52 func WriteFileAllFrom(filename string, r io.Reader, dirperm, fileperm os.FileMode) error { 53 return os_.WriteFileAllFrom(filename, r, dirperm, fileperm) 54 } 55 56 // AppendAll appends data to a file named by filename. 57 // If the file does not exist, AppendAll creates it with mode 0666 (before umask) 58 // If the dir does not exist, AppendAll creates it with 0755 (before umask) 59 // (before umask); otherwise AppendAll appends it before writing, without changing permissions. 60 // 61 // As of Go 1.16, this function simply calls os.AppendAll. 62 func AppendAll(filename string, data []byte) error { 63 return os_.AppendAll(filename, data) 64 } 65 66 // AppendFileAll is the generalized open call; most users will use AppendAll instead. 67 // It appends data to a file named by filename. 68 // If the file does not exist, AppendFileAll creates it with permissions fileperm (before umask) 69 // If the dir does not exist, AppendFileAll creates it with permissions dirperm (before umask) 70 // otherwise AppendFileAll appends it before writing, without changing permissions. 71 // 72 // As of Go 1.16, this function simply calls os.AppendFileAll. 73 func AppendFileAll(filename string, data []byte, dirperm, fileperm os.FileMode) error { 74 return os_.AppendFileAll(filename, data, dirperm, fileperm) 75 } 76 77 // AppendAllFrom appends data to a file named by filename from r until EOF or error. 78 // If the file does not exist, AppendAllFrom creates it with mode 0666 (before umask) 79 // If the dir does not exist, AppendAllFrom creates it with 0755 (before umask) 80 // (before umask); otherwise AppendAllFrom appends it before writing, without changing permissions. 81 // 82 // As of Go 1.16, this function simply calls os.AppendAllFrom. 83 func AppendAllFrom(filename string, r io.Reader) error { 84 return os_.AppendAllFrom(filename, r) 85 } 86 87 // AppendFileAllFrom is the generalized open call; most users will use AppendFileFrom instead. 88 // It appends data to a file named by filename from r until EOF or error. 89 // If the file does not exist, AppendFileAllFrom creates it with permissions fileperm (before umask) 90 // If the dir does not exist, AppendFileAllFrom creates it with permissions dirperm (before umask) 91 // otherwise AppendFileAllFrom appends it before writing, without changing permissions. 92 // 93 // As of Go 1.16, this function simply calls os.AppendFileAllFrom. 94 func AppendFileAllFrom(filename string, r io.Reader, dirperm, fileperm os.FileMode) error { 95 return os_.AppendFileAllFrom(filename, r, dirperm, fileperm) 96 } 97 98 // WriteRenameAll writes data to a temp file and rename to the new file named by filename. 99 // If the file does not exist, WriteRenameAll creates it with mode 0666 (before umask) 100 // If the dir does not exist, WriteRenameAll creates it with 0755 (before umask) 101 // otherwise WriteRenameAll truncates it before writing, without changing permissions. 102 // 103 // As of Go 1.16, this function simply calls os.WriteRenameAll. 104 func WriteRenameAll(filename string, data []byte) error { 105 return os_.WriteRenameAll(filename, data) 106 } 107 108 // WriteRenameFileAll is the generalized open call; most users will use WriteRenameAll instead. 109 // WriteRenameFileAll is safer than WriteFileAll as before Write finished, nobody can find the unfinished file. 110 // It writes data to a temp file and rename to the new file named by filename. 111 // If the file does not exist, WriteRenameFileAll creates it with permissions fileperm 112 // If the dir does not exist, WriteRenameFileAll creates it with permissions dirperm 113 // (before umask); otherwise WriteRenameFileAll truncates it before writing, without changing permissions. 114 // 115 // As of Go 1.16, this function simply calls os.WriteRenameFileAllFrom. 116 func WriteRenameFileAll(filename string, data []byte, dirperm os.FileMode) error { 117 return os_.WriteRenameFileAll(filename, data, dirperm) 118 } 119 120 // WriteRenameAllFrom writes data to a temp file from r until EOF or error, and rename to the new file named by filename. 121 // WriteRenameAllFrom is safer than WriteAllFrom as before Write finished, nobody can find the unfinished file. 122 // If the file does not exist, WriteRenameAllFrom creates it with mode 0666 (before umask) 123 // If the dir does not exist, WriteRenameAllFrom creates it with 0755 (before umask) 124 // otherwise WriteRenameAllFrom truncates it before writing, without changing permissions. 125 // 126 // As of Go 1.16, this function simply calls os.WriteRenameAllFrom. 127 func WriteRenameAllFrom(filename string, r io.Reader) error { 128 return os_.WriteRenameAllFrom(filename, r) 129 } 130 131 // WriteRenameFileAllFrom is the generalized open call; most users will use WriteRenameAllFrom instead. 132 // WriteRenameFileAllFrom is safer than WriteRenameAllFrom as before Write finished, nobody can find the unfinished file. 133 // It writes data to a temp file and rename to the new file named by filename. 134 // If the file does not exist, WriteRenameFileAllFrom creates it with permissions fileperm 135 // If the dir does not exist, WriteRenameFileAllFrom creates it with permissions dirperm 136 // (before umask); otherwise WriteRenameFileAllFrom truncates it before writing, without changing permissions. 137 // 138 // As of Go 1.16, this function simply calls os.WriteRenameFileAllFrom. 139 func WriteRenameFileAllFrom(filename string, r io.Reader, dirperm os.FileMode) error { 140 return os_.WriteRenameFileAllFrom(filename, r, dirperm) 141 } 142 143 // TempAll creates a new temporary file in the directory dir, 144 // opens the file for reading and writing, and returns the resulting *os.File. 145 // If the file does not exist, TempAll creates it with mode 0600 (before umask) 146 // If the dir does not exist, TempAll creates it with 0755 (before umask) 147 // otherwise TempAll truncates it before writing, without changing permissions. 148 // 149 // As of Go 1.16, this function simply calls os.TempAll. 150 func TempAll(dir, pattern string) (f *os.File, err error) { 151 return os_.TempAll(dir, pattern) 152 } 153 154 // TempFileAll is the generalized open call; most users will use TempAll instead. 155 // If the directory does not exist, it is created with mode dirperm (before umask). 156 // 157 // As of Go 1.16, this function simply calls os.TempFileAll. 158 func TempFileAll(dir, pattern string, dirperm os.FileMode) (f *os.File, err error) { 159 return os_.TempFileAll(dir, pattern, dirperm) 160 }