sync: Return the reader from importer instead of writing to a given Writer
This commit is contained in:
parent
f4c3f1e15e
commit
541e32e10b
4 changed files with 34 additions and 26 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package sync
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
|
|
@ -78,30 +77,26 @@ func (i CloudImporter) importFile(URI string, next func(string, string) (interfa
|
|||
return ImportFile(i, URI, next)
|
||||
}
|
||||
|
||||
func (i CloudImporter) getFile(filename string, writer *bufio.Writer) error {
|
||||
func (i CloudImporter) getFile(filename string) (io.Reader, error) {
|
||||
fullURL := i.baseDAV
|
||||
fullURL.Path = path.Join(fullURL.Path, filename)
|
||||
|
||||
client := http.Client{}
|
||||
if req, err := http.NewRequest("GET", fullURL.String(), nil); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
} else {
|
||||
req.SetBasicAuth(i.username, i.password)
|
||||
if resp, err := client.Do(req); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
} else {
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return errors.New(resp.Status)
|
||||
resp.Body.Close()
|
||||
return nil, errors.New(resp.Status)
|
||||
} else {
|
||||
reader := bufio.NewReader(resp.Body)
|
||||
reader.WriteTo(writer)
|
||||
writer.Flush()
|
||||
return resp.Body, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i CloudImporter) writeFile(filename string, reader io.Reader) error {
|
||||
|
|
|
|||
Reference in a new issue