AND THE WINNER IS.........


> -----Original Message-----
> From: Brett Handley 
> Have a look at /progress refinement on function Read-net.


;-)


read-net...  - EXACTLY - what I was looking for.


another nifty function... cool thing is that its not a native, and we can source it, 
and then make our own (improved/specific version).


Thanks for everyone who supplied a clue, they are all worthy avenues, and they all 
give usefull info which I will keep handy for other network-based problems.

even remembering the existence of echo...


---------------
PATCH
---------------
here is a version of read-net which makes it more obvious if we know how many bytes we 
are expecting.  The RT version puts an arbitrary 8000 bytes as the value... which will 
make any progress bar invalid.  

this version behaves EXACTLY the same internally (its still allocating an 8k buffer), 
but in the callback hook, it properly gives a none value as the total byte size of the 
remote file.  This way your callback can adapt to only show downloaded bytes instead 
of a percentage (exactly like  "save link as..." in explorer) .



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]
    probe port/locals/headers/content-length
    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 [
        print type? size
        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]
]


-MAx

 

-- 
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.

Reply via email to