Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: hook while downloading from html port [read-net]

From: maximo:meteorstudios at: 15-Apr-2004 19:19

hi, wrt my last mail, the patch was ugly, containing prints and probes... here is a clean version with an example script to show the difference between loading a file for which size is not known and one that is: (as usual beware of wrapping lines...) ;-----------------------------patch------------------------------- read-net: func [ {Read a file from the net (web). Update progress bar. Allow abort.} url [url!] /progress callback {Call func [total bytes] during transfer. Return true.} /local port buffer data size ][ vbug ['read-net url] if error? try [port: open/direct url] [return none] size: either port/locals/headers/content-length [ to-integer port/locals/headers/content-length ][ none ] buffer: make binary! either integer? size [size][8000] set-modes port/sub-port [lines: false binary: true no-wait: true] until [ if not data: wait [60 port/sub-port] [data: true break] if data: copy port/sub-port [append buffer data] all [:callback not callback size length? buffer data: true break] not data ] close port if not data [buffer] ] ;--------------------------------Examples--------------------------------------- data: read-net/progress http://www.rebol.orgfunc [total bytes][print [bytes "/" total] true] data: read-net/progress http://ircuser.org/files/whackpak.wmv func [total bytes][print [bytes "/" total] true] ;---------- btw the second download is really cool... just do a write/binary on it. (its big though... 5,926,535 bytes) -MAx