1
我有這樣的代碼,使用Ruby 2.3.1運行:紅寶石2.3寫入UTF-16LE gzip文件
str = "麥克風訪問被拒絕"
puts str.encoding #=> "UTF-8"
conv = Encoding::Converter.new("UTF-8", "UTF-16LE")
str = conv.convert(str)
puts str.encoding #=> "UTF-16LE"
Zlib::GzipWriter.open("test.gz", encoding: "UTF-16LE") do |gz|
puts str.encoding #=> "UTF-16LE"
gz.write(str)
end
Zlib::GzipReader.open("test.gz") do |gz|
puts gz.read.encoding #=> ASCII-8BIT
gz.read
end
,並返回[無效編碼]
我如何保存文件的方式,它保持編碼爲UTF-16LE?