carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package safefile
2
3import (
4 "io"
5 "os"
6)
7
8func WriteFile(path string, body []byte, mode os.FileMode) error {
9 return Write(path, mode, func(w io.Writer) error { _, err := w.Write(body); return err })
10}
11
12func ReadFile(path string) ([]byte, error) {
13 f, err := OpenFile(path, os.O_RDONLY, 0)
14 if err != nil {
15 return nil, err
16 }
17 defer f.Close()
18 return io.ReadAll(f)
19}
20