From ebf1c53543f1cf71a1052210e341899379a3ed14 Mon Sep 17 00:00:00 2001 From: xzl <771730766@qq.com> Date: Wed, 24 May 2017 14:29:47 +0800 Subject: [PATCH] =?UTF-8?q?http=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=99=A8=E6=94=B9=E6=88=90=E9=BB=98=E8=AE=A4=E4=B8=8D=E6=96=AD?= =?UTF-8?q?=E7=82=B9=E7=BB=AD=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpDownloader.cpp | 14 +++++++++++++- src/Http/HttpDownloader.h | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Http/HttpDownloader.cpp b/src/Http/HttpDownloader.cpp index 13783883..734887d5 100644 --- a/src/Http/HttpDownloader.cpp +++ b/src/Http/HttpDownloader.cpp @@ -65,9 +65,20 @@ void HttpDownloader::onResponseBody(const char* buf, size_t size, size_t recvedS fwrite(buf,size,1,_saveFile); } } - +//string getMd5Sum(const string &filePath){ +// auto fp = File::createfile_file(filePath.data(),"rb"); +// fseek(fp,0,SEEK_END); +// auto sz = ftell(fp); +// char tmp[sz]; +// fseek(fp,0,SEEK_SET); +// auto rd = fread(tmp,1,sz,fp); +// InfoL << sz << " " << rd; +// fclose(fp); +// return MD5(string(tmp,sz)).hexdigest(); +//} void HttpDownloader::onResponseCompleted() { closeFile(); + //InfoL << "md5Sum:" << getMd5Sum(_filePath); _bDownloadSuccess = true; if(_onResult){ _onResult(Err_success,"success",_filePath.data()); @@ -88,6 +99,7 @@ void HttpDownloader::onDisconnect(const SockException &ex) { void HttpDownloader::closeFile() { if(_saveFile){ + fflush(_saveFile); fclose(_saveFile); _saveFile = nullptr; } diff --git a/src/Http/HttpDownloader.h b/src/Http/HttpDownloader.h index 8e73e9b3..028e6ced 100644 --- a/src/Http/HttpDownloader.h +++ b/src/Http/HttpDownloader.h @@ -20,7 +20,7 @@ public: HttpDownloader(); virtual ~HttpDownloader(); //开始下载文件,默认断点续传方式下载 - void startDownload(const string &url,const string &filePath = "",bool bAppend = true); + void startDownload(const string &url,const string &filePath = "",bool bAppend = false); void startDownload(const string &url,const onDownloadResult &cb){ setOnResult(cb); startDownload(url);