http - 在 Rebol 中读取大型二进制文件失败

标签 http rebol

由于 内存不足 错误,以下 Rebol 代码失败:

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的示例因为 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 细化并继续执行并在 read 期间返回整个文件的内容,如果该方案是 HTTP。 :(

关于http - 在 Rebol 中读取大型二进制文件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3033936/

相关文章:

http - 了解用于 http/2 请求和升级的 header HTTP2-Settings 的值

rebol - 如何从键盘上读取红色/rebol 的键

HTTP Cache-Control 和 params 顺序

java - 为什么我看到的页面与维基百科不同?

c - 在C中: Proxy HTTP requests to another server

return - 为什么 return/redo 在调用上下文中评估结果函数,但不评估 block 结果?

rebol - 如何正确解析成对的 html 标签?

rebol - 如何在服务器上启动 Rebol2/View 控制台?

currency - 如何用 R3 钱显示美分?

http - 使用 http.ListenAndServe 的 Golang 端口阻塞(?)