title: Reading binary data in node.js
body: <p>I'm having problems reading binary data in node.js. This is what I do:</p>
  
  <pre><code>$ cat test.js 
  var fs = require('fs'),
      binary = fs.readFileSync('./binary', 'binary').toString('binary');
  process.stdout.write(binary.substring(0, 48));
  $ xxd binary
  00000000: 7f45 4c46 0201 0100 0000 0000 0000 0000  .ELF............
  00000010: 0300 3e00 0100 0000 0008 0000 0000 0000  ..&gt;.............
  00000020: 4000 0000 0000 0000 10a0 0000 0000 0000  @...............
  $ node test.js | xxd
  00000000: 7f45 4c46 0201 0100 0000 0000 0000 0000  .ELF............
  00000010: 0300 3e00 0100 0000 0008 0000 0000 0000  ..&gt;.............
  00000020: 4000 0000 0000 0000 10c2 a000 0000 0000  @...............
  00000030: 00                                       .
  $
  </code></pre>
  
  <p>Notice how a 0xc2 byte is inserted at index 0x29 when reading with node. Why is that? I've stated binary encoding both to <code>readFileSync</code> and <code>toString</code>.
  I've also tried ascii but then I get a different and equally wrong result.</p>