【发布时间】:2019-07-14 11:52:08
【问题描述】:
我需要在 Ruby 中检测文件类型和编码。
我目前正在通过magic gem 使用 libmagic,但它有一个问题:如果 UTF-16 文件没有 BOM,它不会检测到它们。 This 是此类文件的一个示例。
$ file -i text_without_bom.txt
text_without_bom.txt: application/octet-stream; charset=binary
我可以使用任何其他库或方法来正确检测 UTF-16 文件吗?
P。 S. 也尝试过rchardet 和charlock_holmes,但运气不佳。
【问题讨论】:
-
file确实擅长它的工作,但它仍然有局限性。 -
试试
puts Encoding.list看看你遇到了什么。
标签: ruby character-encoding utf-16 utf-16le