Writing JPG file not working

I'm trying to save a JPG file using appjs.. The code I use is from the sample here. As you can see, I simply passed the fileContent into nodejs's writeFile(). It works, but the resulting JPG image doesn't open (IrfanView shows the error "Not a JPEG file: starts with 0xc3 0xbf". Am I missing something? encoding?

Here's the full code I'm using for the drag and drop and save thing. Pretty straightforward:-

addEventListener('app-ready', function(e){
  var fs   = require('fs');

var readEnd = function(progressEvent) {
    console.log('readEnd',progressEvent,this);
    var fileReader = this;
    var fileContent = fileReader.result;
    var fileName = fileReader.file.name;
    // Note you can not retreive file path, for security reasons. 
    // But you are not supposed to need it, you already have the content ;)
    fs.writeFile("test.jpg", fileContent, function (err) {
      if (err) throw err;
      console.log('It\'s saved!');
    });
    console.log('readEnd:');
}


var readFile = function(file) {
    var reader = new FileReader();
    reader.file = file; // We need it later (filename)
    reader.addEventListener('loadend', readEnd, false);
    reader.readAsBinaryString(file);
}

var drop = function(event) {
    event.preventDefault();
    var dt = event.dataTransfer;
    var files = dt.files;
    for (var i = 0; i<files.length; i++) {
        var file = files[i];
        readFile(file);
    }
}

window.addEventListener("drop", drop);
  window.dispatchEvent(new Event('app-done'));
});

Here is the ZIP file containing the original JPG and the resulting JPG : http://ge.tt/4iYy9Kk/v/0?c