Page 1 of 1

ReceiveHTTPFile Callback

Posted: Wed Dec 25, 2013 5:22 am
by Suirad
Would be nice to be able to pass an optional callback function to the ReceiveHTTPFile() function. Just something that passes either the bytes received so far, or both the bytes received and the total. Its unfortunate to have to rewrite the entire ReceiveHTTPFile() by hand just to have this bit of data exposed by it.

would look something like this: ReceiveHTTPFile(URL$, Filename$ [, @Callback() ])

A code example would look like:

Code: Select all

InitNetwork()
Procedure mycallback(bytessofar.l, totalbytes.l)
  debug "Download progress: "+Str(bytessofar)+"/"+Str(totalbytes)+"
EndProcedure
url = "http://www.purebasic.com/index.php3"
file = GetTemporaryDirectory()+GetURLPart(url, #PB_URL_Path)
If ReceiveHttpFile(url, file, @mycallback())
  debug "Download Completed"
Else
  debug "Download Failed"
EndIf
End
It could also be extended to handle simple returns from the callback. Such as cancelling the download if the callback returns a negative. Ect. ect.