由于内存不足错误,以下Rebol代码失败: read/binary http://mirror.bytemark.co.uk/ubuntu-releases/lucid/ ubuntu-10.04-desktop-i386.iso 如何使用Rebol通过HTTP读取大型二进制文件? Rebol 2端口有点混乱.所以你不
read/binary http://mirror.bytemark.co.uk/ubuntu-releases/lucid/ ubuntu-10.04-desktop-i386.iso
如何使用Rebol通过HTTP读取大型二进制文件?
Rebol 2端口有点混乱.所以你不能直接应用如何 read a large file in parts的样本,因为读取不适用于端口!在R2(更少阅读/部分工作).但是如果你跳过一些箍并使用/ 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中,您可以从端口读取和写入!这意味着理论上修改大文件样本应该有效…
; 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,则在读取期间返回整个文件的内容.