7

Is there a way to read files encoded in UTF-8 with BOM (Byte order marks) on Ruby v2.5.0?

On Ruby 2.3.1 this used to work:

 csv = CSV.open(file_path, encoding: 'bom|utf-8')

However, on 2.5.0 the following error ocurrs:

  ArgumentError:
    unknown encoding name - bom|utf-8 
romeu.hcf
  • 73
  • 1
  • 7

2 Answers2

2

You can try this as well:

File.open(file_path, "r:bom|utf-8")

vdz
  • 21
  • 3
0

You can try this:

require 'file_with_bom'

File.open(file_path, "w:utf-8", :bom => true ) do |csv|

end

it works well

Ulysse BN
  • 10,116
  • 7
  • 54
  • 82