aboutsummaryrefslogtreecommitdiff
path: root/file.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-09-18 15:09:53 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-09-18 15:09:53 +0200
commit83e37e3326921806642351c59761b16919c10e72 (patch)
tree78f27e9537ce1e9ad53b2400549c7d3f5ce861f1 /file.go
parentf24d0f7933e6df09fb33bd65e2af85e6c2a23031 (diff)
Add EncodeFile
Diffstat (limited to 'file.go')
-rw-r--r--file.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/file.go b/file.go
index e321695..eaee236 100644
--- a/file.go
+++ b/file.go
@@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"errors"
+ "fmt"
"io/ioutil"
"os"
"strings"
@@ -57,3 +58,17 @@ func ParseFile(fname string) (File, error) {
Body: body,
}, nil
}
+
+func (f File) EncodeFile(fname string) error {
+ fd, err := os.Create(fname)
+ if err != nil {
+ return err
+ }
+ defer fd.Close()
+ fmt.Fprintln(fd, commentHdr, f.Comment)
+ fmt.Fprintln(fd, string(f.B64))
+ if f.Body != nil {
+ fmt.Fprintln(fd, string(f.Body))
+ }
+ return nil
+}