1
我從Ruby 1.8.7升級到1.9.2(和Rails 3.2.2),並且存在Net :: FTP#gettextfile拋出Encoding的問題: :UndefinedConversionErrorRuby 1.9 + Net :: FTP => Encoding :: UndefinedConversionError
我試圖下載一個編碼爲utf-8的xml文件。下載工作正常,如果我使用getbinaryfile,但我想了解爲什麼gettextfile不起作用。
# -*- encoding : utf-8 -*-
# working
ftp = Net::FTP.open(host,user,password)
ftp.passive = true
ftp.getbinaryfile("some.xml","tmp/some.xml")
# not working
ftp = Net::FTP.open(host,user,password)
ftp.passive = true
# raises Encoding::UndefinedConversionError: "\xFF" from ASCII-8BIT to UTF-8
ftp.gettextfile("some.xml","tmp/some.xml")
我知道,我可以通過外部和內部的編碼,如果使用File.open這樣的:
File.open("some.xml", "r:ASCI-8BIT:UTF-8")
,但無法找到像這樣的Net :: FTP的選項。
我也嘗試過gettextfile的塊版本,但是這不起作用,並給出相同的錯誤信息。
File.open("some.xml", "w:ASCII-8BIT:UTF-8") do |file|
ftp.gettextfile("some.xml") { |line| file.write line }
end
有沒有人知道這裏有什麼問題?