title: Ruby Encoding While File Writing
body: <p>I have a bunch of pdf/txt/msg files I'm trying to download in the ruby console and either move to a local directory or re-upload to another destination.</p>
  
  <p>To start, I've just been trying to read the file and write it to a local directory like so:</p>
  
  <pre><code>path = File.join 'temp', doc_name
  file = File.new(path, 'w')
  file &lt;&lt; Document.find(123).fetch_file  // this function retrieves and decrypts the file from s3
  </code></pre>
  
  <p>The exception I get is: Encoding::UndefinedConversionError: "\xB5" from ASCII-8BIT to UTF-8</p>
  
  <p>I'm wondering how I might be able to get the encoding correct on the file write so that I can download it and open it. It seems like it should be trivial, the answer could be in the decryption or s3 call, but this seemed related to the file write.</p>