WriteFile writes a complete file beneath the root. Creation permissions follow [Root.Create].
(name string, data []byte, filePerm, dirPerm os.FileMode, replace bool)
| 234 | // WriteFile writes a complete file beneath the root. |
| 235 | // Creation permissions follow [Root.Create]. |
| 236 | func (r *Root) WriteFile(name string, data []byte, filePerm, dirPerm os.FileMode, replace bool) (err error) { |
| 237 | file, err := r.Create(name, filePerm, dirPerm, replace) |
| 238 | if err != nil { |
| 239 | return err |
| 240 | } |
| 241 | defer func() { |
| 242 | if closeErr := file.Close(); err == nil && closeErr != nil { |
| 243 | err = closeErr |
| 244 | } |
| 245 | }() |
| 246 | |
| 247 | _, err = file.Write(data) |
| 248 | return err |
| 249 | } |
| 250 | |
| 251 | // CopyFile copies content into a file beneath the root. |
| 252 | // Creation permissions follow [Root.Create]. |