跳轉到內容

Rebol 程式設計/read-thru

來自華夏公益教科書,開放的書籍,為開放的世界
READ-THRU url /progress callback /update /expand /check info /to local-file 

從磁碟快取中讀取網路檔案。返回二進位制資料,否則在錯誤時返回無。

READ-THRU 是一個函式值。

  • url -- (型別:url 檔案)
  • /progress
    • callback -- 在傳輸過程中呼叫 func [總位元組]。返回 true。 (型別:任何)
  • /update -- 強制從源站點更新。
  • /expand -- 傳輸後自動解壓縮。
  • /check -- 僅當版本、校驗和/安全或日期/大小不匹配時更新。
    • info -- (型別:任何)
  • /to -- 指定檔案目標,而不是快取。
    • local-file -- (型別:檔案無)

原始碼

[編輯 | 編輯原始碼]
read-thru: func [
    {Read a net file from thru the disk cache. Returns binary, else none on error.} 
    url [url! file!] 
    /progress callback {Call func [total bytes] during transfer.  Return true.} 
    /update "Force update from source site" 
    /expand "Auto-decompress after transfer." 
    /check {Update only if version, checksum/secure, or date/size do not match.} info 
    /to "Specify a file target, not cache." local-file [file! none!] 
    /local file data purl loc-path
][
    vbug ['read-thru url info update] 
    if none? file: path-thru url [return none] 
    if local-file [file: local-file] 
    if all [not update exists-thru?/check file info] [
        if error? try [data: read/binary file] [return none] 
        return data
    ] 
    if file? url [
        return attempt [read/binary url]
    ] 
    loc-path: first split-path file 
    if data: read-net/progress url :callback [
        if not exists? loc-path [
            if error? try [make-dir/deep loc-path] [return none]
        ] 
        if all [expand find/match data "rebpress"] [
            if error? try [data: decompress skip data 8] [return none]
        ] 
        write/binary file data 
        if all [check block? info info/2] [
            error? try [set-modes file [modification-date: info/2]]
        ]
    ] 
    vbug ['read-thru-ok? found? data] 
    data
]
華夏公益教科書