how change encoding?

M

Marcelo Cavaco

hi everybody,

please help...

i have a file (Documentação.txt) with this structure:

my_data << [0, "Ação", Zlib::Deflate.deflate("Sample Text!!!")].to_a
my_data << [0, "Test", Zlib::Deflate.deflate("Only ASCII
chars!!!")].to_a
my_data << [0, "Test char Ã", Zlib::Deflate.deflate("New test
(Ã)")].to_a

OBS: i not create this file!!!

and i have this code:

require 'fileutils'
require 'zlib'
DestFile = "D:\\temp\\app\\Documentação.txt"
my_read_data = File.open(DestFile, 'rb') { |f| Marshal.load f }
my_read_data.each do |item|
file_path = "D:\\temp\\app\\new_files_" + item[1] + ".txt"
file_text = Zlib::Inflate.inflate(item[2])
File.open(file_path, 'wb') { |file| file.write(file_text) }
end

the result is

new_files_AþÒo.txt
new_files_Test.txt
new_files_Test char â”´.txt

and not

new_files_Ação.txt
new_files_Test.txt
new_files_Test char Ã.txt

why this occurs?

is the encode???

how change ?

OBS: i do not create the file Documentação.txt. i only read it.

PS. be patient. i'm "very" newbiee in ruby.
 
R

Robert Klemme

2010/1/14 Marcelo Cavaco said:
hi everybody,

please help...

i have a file (Documenta=C3=A7=C3=A3o.txt) with this structure:

my_data << [0, "A=C3=A7=C3=A3o", Zlib::Deflate.deflate("Sample Text!!!")]= to_a
my_data << [0, "Test", Zlib::Deflate.deflate("Only ASCII
chars!!!")].to_a
my_data << [0, "Test char =C3=81", Zlib::Deflate.deflate("New test
(=C3=81)")].to_a

OBS: i not create this file!!!

and i have this code:

require 'fileutils'
require 'zlib'
DestFile =3D "D:\\temp\\app\\Documenta=C3=A7=C3=A3o.txt"
my_read_data =3D File.open(DestFile, 'rb') { |f| Marshal.load f }
my_read_data.each do |item|
=C2=A0file_path =3D "D:\\temp\\app\\new_files_" + item[1] + ".txt"
=C2=A0file_text =3D Zlib::Inflate.inflate(item[2])
=C2=A0File.open(file_path, 'wb') { |file| file.write(file_text) }

I'd say you probably rather should open this file in text mode since
you are looking at it in text mode - maybe with a particular encoding
(see link below).
end

the result is

new_files_A=C3=BE=C3=92o.txt
new_files_Test.txt
new_files_Test char =E2=94=B4.txt

and not

new_files_A=C3=A7=C3=A3o.txt
new_files_Test.txt
new_files_Test char =C3=81.txt

why this occurs?

is the encode???
Likely.

how change ?

James has an excellent blog posting about this:
http://blog.grayproductions.net/articles/miscellaneous_m17n_details

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top