Fix download issues

This commit is contained in:
Ben Sarmiento
2023-11-06 02:26:46 +00:00
parent a39c72523d
commit 633e44298e
2 changed files with 11 additions and 8 deletions

View File

@@ -114,16 +114,14 @@ func (d *Downloader) downloadFromAPI(request *Request, buffer []byte, delay int6
downloadURL := resp.Download
req, err := http.NewRequest("GET", downloadURL, nil)
if nil != err {
d.log.Debugf("%v", err)
d.log.Debugf("request init error: %v", err)
return fmt.Errorf("could not create request object %s %s from API", request.file.Path, request.file.Link)
}
req.Header.Add("Range", fmt.Sprintf("bytes=%v-%v", request.offsetStart, request.offsetEnd-1))
d.log.Debugw("Sending HTTP Request %v", req)
res, err := http.DefaultClient.Do(req)
if nil != err {
d.log.Debugf("%v", err)
d.log.Debugf("request error: %v", err)
return fmt.Errorf("could not request object %s %s from API", request.file.Path, request.file.Link)
}
defer res.Body.Close()
@@ -139,8 +137,8 @@ func (d *Downloader) downloadFromAPI(request *Request, buffer []byte, delay int6
}
n, err := io.ReadFull(reader, buffer[:res.ContentLength:cap(buffer)])
if nil != err {
d.log.Debugf("%v", err)
if nil != err && err != io.ErrUnexpectedEOF {
d.log.Debugf("response read error: %v", err)
return fmt.Errorf("could not read objects %s %s API response", request.file.Path, request.file.Link)
}
d.log.Debugf("Downloaded %v bytes of %s %s", n, request.file.Path, request.file.Link)