Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no_translation error while attempting to write unicode characters to file in Elixir

I have a stream that I'm reading from and in turn am writing to a file however I am getting an error that is caused by the presence of a . I assume this is because I'm opening the file w/ the wrong encoding or something but I don't know how to properly set it:

file = File.open!("/some/path.csv", [:write])
IO.write(file, "’")

This results in the following error:

** (ErlangError) erlang error: :no_translation (stdlib) :io.put_chars(#PID<0.250.0>, :unicode, "’")

like image 579
Kyle Decot Avatar asked Jun 22 '16 13:06

Kyle Decot


1 Answers

You should open the file in :utf8 mode.

file = File.open!("/tmp/foo.txt", [:write, :utf8])
IO.write(file, "’")
like image 136
tom Avatar answered Sep 21 '22 09:09

tom