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 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) { func newFileSender(path string) (io.Writer, error) {
f, err := os.Create(path) f, err := os.Create(path)
if err != nil { if err != nil {
@ -209,18 +196,11 @@ func newFileSender(path string) (io.Writer, error) {
return &fileSender{file: f}, nil return &fileSender{file: f}, nil
} }
func (s *fileSender) load(d []byte) error { // Write implements io.Writer.
s.data = d func (s *fileSender) Write(d []byte) (int, error) {
return nil 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() } func (s *fileSender) close() error { return s.file.Close() }
// mtsSender implements loadSender and provides sending capability specifically // mtsSender implements loadSender and provides sending capability specifically