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

发布于 2024-09-05 11:36:45 字数 240 浏览 2 评论 0原文

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

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

How can I use Rebol to read Large bin files over HTTP?

The following Rebol code fails due to an out of memory error:

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

How can I use Rebol to read large binary files over HTTP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

捶死心动 2024-09-12 11:36:45

Rebol 2 端口有些混乱。因此,您不能直接应用如何分段读取大文件的示例因为 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

(更新:我没有请注意 Sunanda 引用的 READ-IO 示例,因为我不太使用 R2,也没有见过 READ-IO。它可能也可以在 http 上工作并且具有更好的性能,但我会让你

在 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,则在读取期间继续细化并返回整个文件的内容。 :(

Rebol 2 ports are something of a mess. So you can't directly apply the sample of how to read a large file in parts because read doesn't work on port! in R2 (much less does read/part work).

But if you jump through some hoops and use the /direct refinement to directly open the file, you get something that will work:

; 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

(UPDATE: I didn't notice the READ-IO sample that Sunanda cites, as I don't use R2 much and hadn't ever seen READ-IO. It may also work on http and have better performance. But I'll let you do that comparison. :P)

In Rebol 3, you can read and write from a port!. That means a modification of the large file sample should work, in theory...

; 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

Yet there's a bug in the current build of R3 alpha that ignores the /part refinement and goes ahead and returns the contents of the whole file during read if the scheme is HTTP. :(

半透明的墙 2024-09-12 11:36:45

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

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

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

A straight read of a large file may fail as it is held in memory and may exhaust the available memory.

This reference describes a way to read a file in chunks, provided you can find an FTP server to source it:
http://www.rebol.com/docs/core23/rebolcore-13.html#section-11.12

A quick search suggests there are FTP servers for Ubuntu, but I have not checked if they cover the version you need. Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文