title: Writing binary data from a Nodejs buffer to a blob on Meteor client
body: <p>I'm trying to create a CSV file that will be saved with UTF-16LE encoding on the server and then pass the result to the client. This is what I do, in Coffeescript:</p>
  
  <pre><code>Meteor.methods {
      iconv: (data, from="UTF-8", to="UTF-16LE") -&gt;
          Iconv = Meteor.require('iconv').Iconv
          iconv = new Iconv(from, to)
          res = iconv.convert(data) 
          res
  }
  </code></pre>
  
  <p>Now if I write the file from the server with the line</p>
  
  <pre><code>fs.writeFileSync('/tmp/test.csv', res)
  </code></pre>
  
  <p>the file is correctly generated. However, I would like to avoid creating a file on the server and save it directly on the client (using the <a href="https://github.com/eligrey/FileSaver.js/" rel="nofollow">filesaver library</a>). The sample client code looks like this:</p>
  
  <pre><code>exportToCsv = (data="tête", filename) -&gt;
      callback = (err, res) -&gt;
          blob = new Blob([res], {type:'text/csv;charset=UTF-16LE'})
          saveAs(blob, filename)
      Meteor.call('iconv', data, callback)
  </code></pre>
  
  <p>As you can see, the data I'm testing with is a simple string with a special character (the 'ê'). My problem is that I cannot pass the nodejs buffer to the client. It is automatically serialised into:</p>
  
  <pre><code>Object {0: 116, 1: 0, 2: 234, 3: 0, 4: 116, 5: 0, 6: 101, 7: 0}
  </code></pre>
  
  <p>instead of the buffer output that I get on the server:</p>
  
  <pre><code>&lt;Buffer 74 00 ea 00 74 00 65 00&gt;
  </code></pre>
  
  <p>The problem is not so much the conversion from hexadecimal to decimal, I know I can convert back to hexadecimal using something <code>Number(116).toString(16)</code>. But how do I write this data as binary in the blob?</p>