WriteFileSync is the same as bufio.WriteFile, but syncs the data before closing.
(filename string, data []byte, perm os.FileMode)
| 18 | |
| 19 | // WriteFileSync is the same as bufio.WriteFile, but syncs the data before closing. |
| 20 | func WriteFileSync(filename string, data []byte, perm os.FileMode) error { |
| 21 | f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm) |
| 22 | if err != nil { |
| 23 | return err |
| 24 | } |
| 25 | if _, err := f.Write(data); err != nil { |
| 26 | return err |
| 27 | } |
| 28 | if err := f.Sync(); err != nil { |
| 29 | return err |
| 30 | } |
| 31 | return f.Close() |
| 32 | } |
| 33 | |
| 34 | // WalkPathFunc walks the directory 'dir' and collects all path names matched by |
| 35 | // func f. If the path is a directory, it will set the bool argument to true. |