Created
          October 6, 2020 13:56 
        
      - 
      
- 
        Save rjhancock/eccbee2203148b1b1954cc5b168ddc1b to your computer and use it in GitHub Desktop. 
    Convert CRLF -> LF and Enforce UTF-8 File Format
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | files = Dir['**/*.blk'] | |
| files += Dir['**/*.mtf'] | |
| files.each do |file| | |
| puts "Checking file: #{file}" | |
| raw = File.read(file) | |
| # New Line Conversion from CRLF -> LF | |
| data = raw.encode(raw.encoding, universal_newline: true) | |
| # Convert to valid UTF-8 | |
| data = data.unpack('C*').pack('U*') if !(data.encoding.name == 'UTF-8' && data.valid_encoding?) | |
| File.write(file, data) | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment