Created
May 22, 2017 13:15
-
-
Save tvandervossen/29a6ef984753a5250a575864e13e6ceb to your computer and use it in GitHub Desktop.
Read and convert any text file to UTF-8 in Ruby
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
require 'tedrahcu' | |
data = IO.binread(path) | |
encoding = Tedrahcu.detect(data) | |
data.force_encoding(encoding).encode!('UTF-8', invalid: :replace, undef: :replace, replace: '', universal_newline: true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment