title: How can I write a file in ISO-8859-1 with Chrome's File API
body: <p>At the moment I am writing a file like this:</p>
  
  <pre><code>var blob = new Blob([contents], {type: 'text/plain;charset=iso-8859-1'});
  fileWriter.write(blob);
  </code></pre>
  
  <p>However, when I run <code>file -i</code> on the resulting file the charset is always UTF-8.</p>
  
  <p>The variable <code>contents</code> is encoded in ISO-8859-1 on the server side, and then communicated over the wire in base64:</p>
  
  <pre><code>def write_csv_file
    filewriter = RMS::LabelFile.for_order(self.order)
    csv = filewriter.to_csv
    csv = csv.encode("ISO-8859-1")
    csv = Base64.encode64(csv)
    %Q{&lt;script type="text/javascript" charset="ISO-8859-1"&gt;
          var csv_data = #{csv.inspect.gsub('\n', '')};
          csv_data = window.atob(csv_data);
          parent.phn.filewriter.writeFile("#{self.order.order_number}.csv", csv_data, 'ISO-8859-1');
        &lt;/script&gt;
    }
  end
  </code></pre>
  
  <p>I've checked and double checked that the encoding is still ISO-8859-1 on the client side in the javascript. It seems like Blob and fileWriter are changing the encoding before they write. Examining the <a href="http://www.w3.org/TR/FileAPI/#constructorBlob" rel="nofollow">W3C's working draft</a> it seems as though Blob converts DOMStrings to UTF-8 before writing them.</p>