add WriteUnstructuredFilePath function to simplify file writing logic

This commit is contained in:
adman
2026-05-03 16:22:17 +02:00
parent 66f86c5599
commit c560966177
+10 -1
View File
@@ -18,7 +18,16 @@ func ReadFile(file io.Reader, data any) (err error) {
return Format.Decode(n.Value, data)
}
func WriteUnstructuredFile(file io.Writer, n Tag) (err error) {
func WriteUnstructuredFilePath(path string, n *Tag) (err error) {
f, err := os.Create(path)
if err != nil {
return
}
defer f.Close()
return WriteUnstructuredFile(f, n)
}
func WriteUnstructuredFile(file io.Writer, n *Tag) (err error) {
gzw := gzip.NewWriter(file)
defer gzw.Close()
err = n.Encode(gzw)