Vote count: 0
I have this code, running with Ruby 2.3.1:
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
and returns [Invalid encoding]
How can I save file in a way that it keeps the encoding as UTF-16LE?
asked 25 secs ago
Ruby 2.3 write UTF-16LE gzip file
Aucun commentaire:
Enregistrer un commentaire