M file.go => file.go +7 -3
@@ 63,9 63,9 @@ func (f *file) SetError(err error) {
f.err = err
}
-func (f *file) Data() *bytes.Buffer {
+func (f *file) Bytes() []byte {
if f.buff != nil {
- return f.buff
+ return f.buff.Bytes()
}
var buff bytes.Buffer
@@ 84,5 84,9 @@ func (f *file) Data() *bytes.Buffer {
}
f.buff = &buff
- return f.buff
+ return f.buff.Bytes()
+}
+
+func (f *file) SetBytes(data []byte) {
+ f.buff = bytes.NewBuffer(data)
}
M goldsmith.go => goldsmith.go +2 -2
@@ 125,7 125,7 @@ func (gs *goldsmith) Complete(dstDir string) []File {
var files []File
for file := range s.output {
- data := file.Data()
+ data := file.Bytes()
if data == nil {
continue
}
@@ 137,7 137,7 @@ func (gs *goldsmith) Complete(dstDir string) []File {
continue
}
- if err := ioutil.WriteFile(absPath, data.Bytes(), 0644); err != nil {
+ if err := ioutil.WriteFile(absPath, data, 0644); err != nil {
file.SetError(err)
continue
}
M types.go => types.go +2 -3
@@ 22,8 22,6 @@
package goldsmith
-import "bytes"
-
type Context interface {
NewFile(path string) File
}
@@ 38,7 36,8 @@ type File interface {
Error() error
SetError(err error)
- Data() *bytes.Buffer
+ Bytes() []byte
+ SetBytes(bytes []byte)
}
type ProcessorMultiple interface {