Rebol Programming/request-download

From Wikibooks, open books for an open world
Jump to navigation Jump to search

USAGE:[edit | edit source]

REQUEST-DOWNLOAD url /to local-file 

DESCRIPTION:[edit | edit source]

Request a file download from the net. Show progress. Return none on error.

REQUEST-DOWNLOAD is a function value.

ARGUMENTS[edit | edit source]

  • url -- (Type: url)

REFINEMENTS[edit | edit source]

  • /to -- Specify local file target.
    • local-file -- (Type: file none)

SOURCE CODE[edit | edit source]

request-download: func [
    {Request a file download from the net. Show progress. Return none on error.} 
    url [url!] 
    /to "Specify local file target." local-file [file! none!] 
    /local prog lo stop data stat event-port event
][
    view/new center-face lo: layout [
        backeffect [gradient 1x1 water gray] 
        space 10x8 
        vh2 300 gold "Downloading File:" 
        vtext bold center 300 to-string url 
        prog: progress 300 
        across 
        btn 90 "Cancel" [stop: true] 
        stat: text 160x24 middle
    ] 
    stop: false 
    data: read-thru/to/progress/update url local-file func [total bytes] [
        prog/data: bytes / (max 1 total) 
        stat/text: reform [bytes "bytes"] 
        show [prog stat] 
        not stop
    ] 
    unview/only lo 
    if not stop [data]
]