Page 1 of 1
file size not updating while downloading file
Posted: Mon Dec 23, 2013 8:59 pm
by Suirad
I have a program that downloads files with the standard library (receivehttpfile()).While the download is happening, in another thread i am having the file size updated on that file.
Something strange is happening though. Only after large chunks of the file being downloaded, will the size returned by filesize() actually update. But, if i navigate to the folder that the file is being downloaded to in windows explorer and/or refresh if am already there, it will update the size in both explorer AND the size returned by filesize().
I dont have time at the moment to make an example, but i can if needed later on.
Thanks for your time.
Re: file size not updating while downloading file
Posted: Mon Dec 23, 2013 9:34 pm
by IdeasVacuum
If you are displaying the value in a StringGadget(), use a TextGadget() instead. After updating the TextGadget(), While WindowEvent() : Wend
Re: file size not updating while downloading file
Posted: Tue Dec 24, 2013 10:23 am
by Suirad
I am using a text gadget, and its not an issue with the gadget updating. The problem is that that the filesize() function returns the same thing for about 5-10 seconds at a time while the download is happening in another thread(checked debug output to verify).
The strange part is that if i navigate to the folder where the file is being saved to and hit refresh, it updates the file size on windows explorer AND the return of the filesize function starts showing a newer value.
Re: file size not updating while downloading file
Posted: Tue Dec 24, 2013 11:44 am
by IdeasVacuum
... I think we will need a code snippet that demonstrates the issue. Wouldn't it be better if the filesize() function was in the same thread as the download?
Re: file size not updating while downloading file
Posted: Tue Dec 24, 2013 12:18 pm
by Suirad
I plan to add a snippet after i get home from work. No, the download is put in a seperate thread so that it doesnt hang the main application window. filesize is being used from the main thread to get a download progress by comparing the current filesize to the final file size.
Re: file size not updating while downloading file
Posted: Tue Dec 24, 2013 6:09 pm
by Demivec
You can use PostEvent() from the thread to indicate progress to the main thread where the update of the gadget occurs.
Re: file size not updating while downloading file
Posted: Tue Dec 24, 2013 8:16 pm
by Jagermeister
Filesize() is returned at the whim of the OS, no? Windows' own subsystem doesn't report transfers bit-for-bit so I wouldn't rely on that as a live progress marker. I think ReceiveHTTPFile is more of a set-it-and-forget-it implementation as opposed to ReceiveFTPFile which has FTPProgress. Some nice magic using ReceiveNetworkData in TerryHough's example:
http://www.purebasic.fr/english/viewtop ... 13&t=50016
Also found this interesting tidbit: "When sending small files, the headers can be a significant part of the amount of actual data transfered."
http://daniel.haxx.se/docs/ftp-vs-http.html