Skip to content

Instantly share code, notes, and snippets.

@j05h
Created June 14, 2015 16:13
Show Gist options
  • Save j05h/ad71379fb65b8ef69278 to your computer and use it in GitHub Desktop.
Save j05h/ad71379fb65b8ef69278 to your computer and use it in GitHub Desktop.
Stupid simple way of detecting file encoding
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
@j05h
Copy link
Author

j05h commented Jun 14, 2015

Emphasis on stupid... If you're looking for something good, look at https://github.com/brianmario/charlock_holmes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment