From 4cda9273dac861f6c67ec9828ee32f928def4ffd Mon Sep 17 00:00:00 2001 From: "Rahul A. Sutar" <rahuls@mkcl.org> Date: Tue, 25 Jul 2017 17:46:39 +0530 Subject: [PATCH] Update fileutil.go --- downloadhelper/fileutil.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/downloadhelper/fileutil.go b/downloadhelper/fileutil.go index a62026a..bc64a18 100644 --- a/downloadhelper/fileutil.go +++ b/downloadhelper/fileutil.go @@ -61,13 +61,15 @@ func mergeFiles(filename string, count int) { fmt.Println("temp file name : " + tempFilename) fmt.Println("file name : " + filename) + file, err := os.OpenFile(DownloadLocation+"/"+tempFilename, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) + if err != nil { + log.Fatal(err) + } + defer file.Close() + for i := 0; i < count; i++ { partFilename := DownloadLocation + "/temp/" + filename + "_" + strconv.Itoa(i) - file, err := os.OpenFile(DownloadLocation+"/"+tempFilename, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) - if err != nil { - log.Fatal(err) - } - defer file.Close() + reader, err := ioutil.ReadFile(partFilename) reader = reader[16:] if err != nil { @@ -77,6 +79,7 @@ func mergeFiles(filename string, count int) { log.Fatal(err) } } + file.Close() os.Rename(DownloadLocation+"/"+tempFilename, DownloadLocation+"/"+filename) } func isDirEmpty(name string) (bool, error) { -- GitLab