Skip to content

Instantly share code, notes, and snippets.

@picandocodigo
Created April 17, 2012 17:29
Show Gist options
  • Save picandocodigo/2407642 to your computer and use it in GitHub Desktop.
Save picandocodigo/2407642 to your computer and use it in GitHub Desktop.
Read file in latin-1 and write it in UTF-8
file = File.new("/data/test.csv", "w+:utf-8")
open("http://miservidorfalsoquenoexiste.com/archivo.csv", "r:iso-8859-1") do |f|
file.write(f.read)
end
@foca
Copy link

foca commented Apr 17, 2012

Esto funciona sin guardar archivos a disco:

out = StringIO.open("", "w+:utf-8")
out.write open("http://www.mnav.gub.uy/artistas.csv", "r:iso-8859-1").read
puts out.string #=> correctly transcoded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment