Any idea why this ugly solution works:
t = Tempfile.new('f')
t.write(f.content)
t.fsync
puts `iconv -f #{f.detect_charset} -t utf-8 #{t.path}`
But this clean pure Ruby solution fails:
puts Iconv.new(f.detect_charset, ''utf-8').iconv(f.content)
The latter gives this error:
in `iconv': "\310\355\362\345\360\355\345\362-\350\347\344\340\355\350\345"... (Iconv::IllegalSequence)
I have double checked that the file does not have any illegal sequences, and iconv converts it perfectly from the command line.. just not through Iconv in Ruby.
Return to the homepage.
Privacy Policy