gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 16:05:55 24 4
gpt4 key购买 nike

由于 内存不足 错误,以下 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com