forked from fyne-io/fyne-cross
/
save.go
37 lines (31 loc) · 785 Bytes
/
save.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package metadata
import (
"bytes"
"io"
"os"
"path/filepath"
"github.com/BurntSushi/toml"
)
// Save attempts to write a FyneApp metadata to the provided writer.
// If the encoding fails an error will be returned.
func Save(f *FyneApp, w io.Writer) error {
var buf bytes.Buffer
e := toml.NewEncoder(&buf)
err := e.Encode(f)
if err != nil {
return err
}
_, err = w.Write(buf.Bytes())
return err
}
// SaveStandard attempts to save a FyneApp metadata to the `FyneApp.toml` file in the specified dir.
// If the file cannot be written or encoding fails an error will be returned.
func SaveStandard(f *FyneApp, dir string) error {
path := filepath.Join(dir, "FyneApp.toml")
w, err := os.Create(path)
if err != nil {
return err
}
defer w.Close()
return Save(f, w)
}