【问题标题】:Reading large Binary files fails in Rebol在 Rebol 中读取大型二进制文件失败
【发布时间】:2010-06-13 21:14:09
【问题描述】:

以下 Rebol 代码由于 out of memory 错误而失败:

read/binary http://mirror.bytemark.co.uk/ubuntu-releases/lucid/
            ubuntu-10.04-desktop-i386.iso 

如何使用 Rebol 通过 HTTP 读取大型二进制文件?

【问题讨论】:

标签: http rebol


【解决方案1】:

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。 :(

【讨论】:

    【解决方案2】:

    【讨论】:

    • 看起来不错,但它被包装在一个没有名字的上下文中。那么我应该如何使用它呢?我试图提取批量下载功能,但我收到关于缺少括号的奇怪错误。
    • 您可以通过删除上下文来公开它,或者通过创建另一个全局函数来公开它。例如。在上下文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% 时中止了它,因为我不想要这个文件。
    【解决方案3】:

    大文件的直接读取可能会失败,因为它保存在内存中,并且可能会耗尽可用内存。

    本参考描述了一种以块的形式读取文件的方法,前提是您可以找到一个 FTP 服务器来获取它: http://www.rebol.com/docs/core23/rebolcore-13.html#section-11.12

    快速搜索表明有适用于 Ubuntu 的 FTP 服务器,但我没有检查它们是否涵盖了您需要的版本。祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-19
      • 1970-01-01
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      • 2011-03-13
      • 1970-01-01
      相关资源
      最近更新 更多