M file.go => file.go +2 -2
@@ 67,7 67,7 @@ func (f *file) SetError(err error) {
f.err = err
}
-func (f *file) Bytes() []byte {
+func (f *file) Data() []byte {
if f.buff != nil {
return f.buff.Bytes()
}
@@ 91,6 91,6 @@ func (f *file) Bytes() []byte {
return f.buff.Bytes()
}
-func (f *file) SetBytes(data []byte) {
+func (f *file) SetData(data []byte) {
f.buff = bytes.NewBuffer(data)
}
M goldsmith.go => goldsmith.go +10 -4
@@ 23,7 23,6 @@
package goldsmith
import (
- "io/ioutil"
"os"
"path"
"path/filepath"
@@ 41,7 40,7 @@ type goldsmith struct {
files chan File
}
-func NewGoldsmith(src string) Goldsmith {
+func New(src string) Goldsmith {
gs := new(goldsmith)
gs.scan(src)
return gs
@@ 125,7 124,7 @@ func (gs *goldsmith) Complete(dstDir string) []File {
var files []File
for file := range s.output {
- data := file.Bytes()
+ data := file.Data()
if data == nil {
continue
}
@@ 137,7 136,14 @@ func (gs *goldsmith) Complete(dstDir string) []File {
continue
}
- if err := ioutil.WriteFile(absPath, data, 0644); err != nil {
+ f, err := os.Create(absPath)
+ if err != nil {
+ file.SetError(err)
+ continue
+ }
+ defer f.Close()
+
+ if _, err := f.Write(data); err != nil {
file.SetError(err)
continue
}
M types.go => types.go +2 -2
@@ 43,8 43,8 @@ type File interface {
Path() string
SetPath(path string)
- Bytes() []byte
- SetBytes(bytes []byte)
+ Data() []byte
+ SetData(data []byte)
Property(key, def string) interface{}
SetProperty(key string, value interface{})