REBOL Programming/read-net

USAGE:Edit

READ-NET url /progress callback 

DESCRIPTION:Edit

Read a file from the net (web). Update progress bar. Allow abort.

READ-NET is a function value.

ARGUMENTSEdit

  • url -- (Type: url)

REFINEMENTSEdit

  • /progress
    • callback -- Call func [total bytes] during transfer. Return true. (Type: any)

SOURCE CODEEdit

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: to-integer any [port/locals/headers/content-length 8000] 
    buffer: make binary! size 
    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 size not callback size length? buffer data: true break] 
        not data
    ] 
    close port 
    if not data [buffer]
]
Last modified on 13 November 2012, at 10:52