revid: simplified file sender to remove load and send and just do logic in Write

This commit is contained in:
Saxon 2019-04-01 12:11:05 +10:30
parent f17d2ffb8c
commit cdd2537cc3
1 changed files with 3 additions and 23 deletions

View File

@ -188,19 +188,6 @@ type fileSender struct {
data []byte
}
// Write implements io.Writer.
func (s *fileSender) Write(d []byte) (int, error) {
err := s.load(d)
if err != nil {
return 0, err
}
err = s.send()
if err != nil {
return len(d), err
}
return len(d), nil
}
func newFileSender(path string) (io.Writer, error) {
f, err := os.Create(path)
if err != nil {
@ -209,18 +196,11 @@ func newFileSender(path string) (io.Writer, error) {
return &fileSender{file: f}, nil
}
func (s *fileSender) load(d []byte) error {
s.data = d
return nil
// Write implements io.Writer.
func (s *fileSender) Write(d []byte) (int, error) {
return s.file.Write(d)
}
func (s *fileSender) send() error {
_, err := s.file.Write(s.data)
return err
}
func (s *fileSender) release() {}
func (s *fileSender) close() error { return s.file.Close() }
// mtsSender implements loadSender and provides sending capability specifically