2017-04-12 18 views
1

现在还没有真正的红色书籍,因为它是如此的新颖。所以我想跟着一本旧的Rebol书,并且从中拯救我能做的。

我发现了几个命令,例如read,由于文件编码我无法执行代码。

save %/c/users/abagget/desktop/bay.jpg read http://rebol.com/view/bay.jpg 
Access Error: invalid UTF-8 encoding: #{FFD8FFE0} 

在雷博尔这^将已读/二进制和写入/二进制

>> write %/c/alex.txt read http://google.com 
*** Access Error: invalid UTF-8 encoding: #{A050726F} 

有没有办法进入的内容转换为UTF-8,所以我可以做读? 还是有其他类型的处理非UTF-8的读取?

+0

哪本书? :D 这个错误是由谷歌的网页无效的UTF-8引起的,因为你已经发现了.. Rebol根本无视(?)它。我打破了谷歌的错误,但我不记得.. –

+0

了解REBOL 作者:Nick Antonaccio –

回答

3

In Rebol this^ would have been read/binary and write/binary

在红太,save是一个红色的数据类型转换为二进制格式的序列化文本。所以如果你想save到JPEG文件,你需要提供一个image!值。 read获取文本内容(现在仅限于UTF-8),因此您的使用情况无效。正确的路线应该是:

write/binary %/c/users/abagget/desktop/bay.jpg read/binary http://rebol.com/view/bay.jpg 

Is there a way to convert incoming content to UTF-8 so I can do the read?

从非UTF-8文本资源获得一个字符串,你需要获取资源为二进制,然后写一个可怜的人转换器,它应该能正常运行对于常用的Latin-1编码:

bin-to-string: function [bin [binary!]][ 
    text: make string! length? bin 
    foreach byte bin [append text to char! byte] 
    text 
] 

从控制台使用它:

>> bin-to-string read/binary http://google.com 
== {<!doctype html><html itemscope="" itemtype="http://schema.org... 

红会提供p罗伯转换器在未来常用的文本编码。同时,您可以使用此功能,或者为您最常使用的编码编写适当的解码器(使用转换表)。

相关问题