mirror of https://bitbucket.org/ausocean/av.git
revid: simplified file sender to remove load and send and just do logic in Write
This commit is contained in:
parent
f17d2ffb8c
commit
cdd2537cc3
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue