How to write BOM marker to a file in Ruby

后端 未结 2 1180
感情败类
感情败类 2021-01-01 23:15

I have some working code with a crutch to add BOM marker to a new file.

  #writing
  File.open name, \'w\', 0644 do |file|
    file.write \"\\uFEFF\"
    fil         


        
2条回答
  •  旧巷少年郎
    2021-01-01 23:55

    Alas I think your manual approach is the way to go, at least I don't know a better way:

    http://blog.grayproductions.net/articles/miscellaneous_m17n_details

    To quote from JEG2's article:

    Ruby 1.9 won't automatically add a BOM to your data, so you're going to need to take care of that if you want one. Luckily, it's not too tough. The basic idea is just to print the bytes needed at the beginning of a file.

提交回复
热议问题