由于out of memory
错误,以下Rebol代码失败:
read/binary http://mirror.bytemark.co.uk/ubuntu-releases/lucid/
ubuntu-10.04-desktop-i386.iso
如何使用Rebol通过HTTP读取大型二进制文件?
答案 0 :(得分:4)
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 alpha中存在一个错误,忽略了/part
细化并继续前进,如果方案是HTTP,则在read
期间返回整个文件的内容。 :(
答案 1 :(得分:2)
答案 2 :(得分:1)
直接读取大文件可能会失败,因为它被保留在内存中并可能耗尽可用内存。
此参考介绍了一种以块的形式读取文件的方法,前提是您可以找到一个FTP服务器来获取它: http://www.rebol.com/docs/core23/rebolcore-13.html#section-11.12
快速搜索表明Ubuntu有FTP服务器,但我还没有检查它们是否涵盖了你需要的版本。祝你好运!