From 09a445fdd99b8c76286908b954909e6ae987a5af Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 31 Oct 2015 15:57:03 +0900 Subject: [PATCH] Updating interface --- file.go | 10 +++++++--- goldsmith.go | 4 ++-- types.go | 5 ++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/file.go b/file.go index 233a0bd..2c401b4 100644 --- a/file.go +++ b/file.go @@ -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) } diff --git a/goldsmith.go b/goldsmith.go index b3ceb2c..69ac666 100644 --- a/goldsmith.go +++ b/goldsmith.go @@ -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 } diff --git a/types.go b/types.go index 29cb841..67aade7 100644 --- a/types.go +++ b/types.go @@ -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 {