ReceiveHTTPFile Callback

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Suirad
User
User
Posts: 42
Joined: Sun Sep 20, 2009 7:37 pm
Location: Melbourne, Florida, USA

ReceiveHTTPFile Callback

Post 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.