fix: stores.FetchHandler: defer close file and increase buffer size

This commit is contained in:
15ho 2020-12-29 10:07:28 +08:00
parent bb5a92e2f4
commit 5b235db366

View File

@ -116,9 +116,12 @@ func (handler *FetchHandler) remoteGetSector(w http.ResponseWriter, r *http.Requ
w.WriteHeader(500) w.WriteHeader(500)
return return
} }
if !stat.IsDir() {
defer rd.(*os.File).Close()
}
w.WriteHeader(200) w.WriteHeader(200)
if _, err := io.Copy(w, rd); err != nil { // TODO: default 32k buf may be too small if _, err := io.CopyBuffer(w, rd, make([]byte, CopyBuf)); err != nil {
log.Errorf("%+v", err) log.Errorf("%+v", err)
return return
} }