Created
June 14, 2015 16:13
-
-
Save j05h/ad71379fb65b8ef69278 to your computer and use it in GitHub Desktop.
Stupid simple way of detecting file encoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def detect_encoding file | |
result = `file --mime-encoding #{file}` | |
_, encoding = result.split | |
if File.exists? file | |
return encoding unless encoding.nil? || encoding.empty? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Emphasis on stupid... If you're looking for something good, look at https://github.com/brianmario/charlock_holmes