tglogo.png
0 LIKES

Snippet


Download methods by xorc

In Category General IRC Posted by Snippets On 12/07/23
Tags: download xorc 

v2 Signal polling microsoft.xmlhttp (COM):
Calls microsoft.xmlhttp comobject asynchronous and dispatches a signal to check the result, which if isn't done yet signals itself again until the response is received, then calls the provided callback when the contents is written to disk.

Performance / Example:
//echo ticks: $ticks | /XMLHTTPRequest "echo ticks: $($ticks,0) result:" http://www.google.com/ google.html
time: 12:57:24 ticks: 51840640
time: 12:57:24 ticks: 51840687 result: XMLHTTPRequest1393273344 $true http://www.google.com/ google.html
Elapsed 47 ticks
  1. alias XMLHTTPRequest {

  2.   var %callback = $1
  3.   var %URI = $2
  4.   var %path = $3

  5.   if (" isin $1) {
  6.     var %callback = $mid($1-,1,$pos($1-,",2))
  7.     var %args = $replace($1-,%callback,)
  8.     tokenize 32 %args
  9.     unset %args

  10.     var %callback = $noqt(%callback)
  11.     var %URI = $1
  12.     var %path = $2
  13.   }

  14.   var %comid = $+(XMLHTTPRequest,$hash($nopath(%path),32))

  15.   if ($com(%comid)) .comclose %comid
  16.   .comopen %comid microsoft.xmlhttp

  17.   noop $com(%comid,Open,4,bstr,GET,bstr,%URI,bool,1)
  18.   noop $com(%comid,Send,1)

  19.   $+(.,timer,%comid) 1 0 .signal -n %comid $qt(%callback) %URI %path
  20.   $+(.,timer,%comid,timeout,timer) 1 10 .timer $+ %comid off
  21.   $+(.,timer,%comid,timeout,com) 1 10 .comclose %comid
  22. }

  23. on *:SIGNAL:XMLHTTPRequest*: {

  24.   var %comid = $signal
  25.   var %callback = $1
  26.   var %URI = $2
  27.   var %path = $3

  28.   if (" isin $1) {
  29.     var %callback = $mid($1-,1,$pos($1-,",2))
  30.     var %args = $replace($1-,%callback,)
  31.     tokenize 32 %args
  32.     unset %args

  33.     var %callback = $noqt(%callback)
  34.     var %URI = $1
  35.     var %path = $2
  36.   }

  37.   goto $com(%comid,responseText,2)

  38.   :-1 | %callback %comid $false %URI %path | halt
  39.   :0 | $+(.,timer,%comid) 1 0 .signal -n %comid $qt(%callback) %URI %path | halt
  40.   :1
  41.   $+(.,timer,%comid,*) off

  42.   bwrite $5 0 $com(%comid,&binvar).result &binvar

  43.   .comclose %comid

  44.   %callback %comid $true %URI %path
  45. }


Comments 0


Please note that on our website we use cookies necessary for the functioning of our website, cookies that optimize the performance. To learn more about our cookies, how we use them and their benefits, please read our Cookie Policy.
I Understand