Hen*_*ang 3 ruby csv byte-order-mark
中的意思是什么'rb:bom|utf-8':
CSV.open(csv_name, 'rb:bom|utf-8', headers: true, return_headers: true) do |csv|
我可以这么理解:
r意思是读bom是一种\xEF\xBB\xBF在文件开头指示字节顺序的文件格式。utf-8是一种文件格式但:
更新:
找到了一个非常有用的文档: https ://ruby-doc.org/core-2.6.3/IO.html#method-c-new-label-Open+Mode
(接受的答案不是不正确而是不完整)
rb:bom|utf-8转换为人类可读的句子意味着:
打开文件r以二进制模式 ( ) 进行读取 ( b),并查找 Unicode BOM 标记 ( bom) 以检测编码,或者,如果未找到 BOM 标记,则假定为 UTF-8 编码 ( utf-8)。
A BOM marker can be used to detect if a file is UTF-8 or UTF-16 and in case it is UTF-16, whether that is little or big endian UTF-16. There is also a BOM marker for UTF-32, yet Ruby doesn't support UTF-32 as of today. A BOM marker is just a special reserved byte sequence in the Unicode standard that is only used for the purpose of detecting the encoding of a file and it must be the first "character" of that file. It's recommended and typically used for UTF-16 as it exists in two different variants, it's optional for UTF-8 and usually if a file is Unicode but has no BOM marker, it is assumed to be UTF-8.
| 归档时间: |
|
| 查看次数: |
1429 次 |
| 最近记录: |