diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-09-09 03:53:09 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-09-09 03:53:09 -0700 |
| commit | 4fc0bd1a8173e284ff919edb5214f5adf7a90f06 (patch) | |
| tree | 4f6c6f634150ddbcbe992e131315cc0c121c4dcc /weed/command/download.go | |
| parent | 5e13bc878ca63c72f71d1e93a9da44b3debc22df (diff) | |
| download | seaweedfs-4fc0bd1a8173e284ff919edb5214f5adf7a90f06.tar.xz seaweedfs-4fc0bd1a8173e284ff919edb5214f5adf7a90f06.zip | |
return http response directly
Diffstat (limited to 'weed/command/download.go')
| -rw-r--r-- | weed/command/download.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/weed/command/download.go b/weed/command/download.go index 7d4dad2d4..f7588fbf0 100644 --- a/weed/command/download.go +++ b/weed/command/download.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "io/ioutil" + "net/http" "os" "path" "strings" @@ -59,7 +60,7 @@ func downloadToFile(server, fileId, saveDir string) error { if err != nil { return err } - defer rc.Close() + defer util.CloseResponse(rc) if filename == "" { filename = fileId } @@ -71,12 +72,11 @@ func downloadToFile(server, fileId, saveDir string) error { } f, err := os.OpenFile(path.Join(saveDir, filename), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm) if err != nil { - io.Copy(ioutil.Discard, rc) return err } defer f.Close() if isFileList { - content, err := ioutil.ReadAll(rc) + content, err := ioutil.ReadAll(rc.Body) if err != nil { return err } @@ -95,7 +95,7 @@ func downloadToFile(server, fileId, saveDir string) error { } } } else { - if _, err = io.Copy(f, rc); err != nil { + if _, err = io.Copy(f, rc.Body); err != nil { return err } @@ -108,12 +108,12 @@ func fetchContent(server string, fileId string) (filename string, content []byte if lookupError != nil { return "", nil, lookupError } - var rc io.ReadCloser + var rc *http.Response if filename, _, rc, e = util.DownloadFile(fileUrl); e != nil { return "", nil, e } - content, e = ioutil.ReadAll(rc) - rc.Close() + defer util.CloseResponse(rc) + content, e = ioutil.ReadAll(rc.Body) return } |
