以下雷博爾代碼失敗,因爲一個out of memory
錯誤:閱讀大型二進制文件未能在雷博爾
read/binary http://mirror.bytemark.co.uk/ubuntu-releases/lucid/
ubuntu-10.04-desktop-i386.iso
如何使用雷博爾over HTTP來讀取大的二進制文件?
以下雷博爾代碼失敗,因爲一個out of memory
錯誤:閱讀大型二進制文件未能在雷博爾
read/binary http://mirror.bytemark.co.uk/ubuntu-releases/lucid/
ubuntu-10.04-desktop-i386.iso
如何使用雷博爾over HTTP來讀取大的二進制文件?
Rebol 2端口是一團糟。所以你不能直接應用read a large file in parts的示例,因爲read
在R2中不起作用port!
(更不用說read/part
工作)。
但是,如果你跳通過一些箍,並使用/direct
細化,直接打開該文件,你得到的東西,將工作:
; Rebol 2 chunking http download sample
filename: %ubuntu-10.04-desktop-i386.iso
base-url: http://mirror.bytemark.co.uk/ubuntu-releases/lucid/
chunk-size: 32000
in-port: open/binary/direct rejoin [base-url filename]
out-port: open/binary/direct filename
while [not none? data: copy/part in-port chunk-size] [
append out-port data
]
close in-port
close out-port
(更新:我沒有注意到READ- IO示例that Sunanda cites,因爲我沒有使用過多的R2,也沒有看過READ-IO,它也可能在http上工作並且性能更好,但我會讓你做這樣的比較:P)
在Rebol 3中,您可以讀寫port!
。這意味着大文件採樣的修改應該工作,理論上 ...
; Rebol 3 chunking http download sample
; Warning: does not work in A99 release
filename: %ubuntu-10.04-desktop-i386.iso
base-url: http://mirror.bytemark.co.uk/ubuntu-releases/lucid/
chunk-size: 32000
in-port: open/read rejoin [base-url filename]
out-port: open/write filename
while [not empty? data: read/part in-port chunk-size] [
write out-port data
]
close in-port
close out-port
然而,有一個在R3阿爾法的當前版本是忽略/part
細化和前進並返回一個錯誤如果方案是HTTP,則在read
期間整個文件的內容。 :(
直接讀取大文件可能會失敗,因爲它保存在內存中並可能耗盡可用內存。
該文獻中記載的方式來讀取數據塊文件,只要你能找到一個FTP服務器源吧: http://www.rebol.com/docs/core23/rebolcore-13.html#section-11.12
快速搜索表明有FTP服務器,Ubuntu的,但我沒有檢查,如果他們涵蓋了你需要的版本。祝你好運!
似乎很棒,但它被包裹到一個沒有名字的上下文中,所以我該如何使用它? 我試圖提取批量下載功能,但我得到奇怪的錯誤關於丟失括號 – 2010-06-19 15:32:56
您可以通過刪除上下文或通過創建另一個全局函數來公開它。例如,在上下文結束之前 'set'bd:batch-download' 然後你可以使用'bd函數。例如: 'bd/to-dir [http://www.http://mirror.bytemark.co.uk/ubuntu-releases/lucid/ubuntu-10.04-desktop-i386.iso]%downloads /' 開始下載。因爲我不想要這個文件,我以10%的比例中止了它。 – 2010-06-20 01:05:50
這個問題上元話題性:http://meta.stackexchange.com/questions/53547/dealing-with-moderators-who-close -a-question-due-to-igno-of-tagged-languag – 2010-06-14 12:16:09