title: Writing buffer response from resemble.js to file
body: <p>I'm using <a href="https://www.npmjs.com/package/node-resemble-js" rel="nofollow">node-resemble-js</a> to compare two PNG images.</p>
  
  <p>The comparison happens without issue and I get a successful/relevant response however I'm having trouble outputting the image diff.</p>
  
  <pre><code>var express = require('express');
  var fs = require('fs');
  var resemble = require('node-resemble-js');
  var router = express.Router();
  
  router.get('/compare', function(req, res, next) {
      compareImages(res);
  });
  
  var compareImages = function (res) {
      resemble.outputSettings({
          largeImageThreshold: 0
      });
      var diff = resemble('1.png')
          .compareTo('2.png')
          .ignoreColors()
          .onComplete(function(data){
              console.log(data);
              var png = data.getDiffImage();
              fs.writeFile('diff.png', png.data, null, function (err) {
                  if (err) {
                      throw 'error writing file: ' + err;
                  }
                  console.log('file written');
              });
              res.render('compare');
          });
  };
  
  module.exports = router;
  </code></pre>
  
  <p>It writes to diff.png as expected however it's not creating a valid image.</p>
  
  <p>Any ideas where I'm going wrong? Feel like I'm pretty close but just unsure of final piece.</p>
  
  <p>Thanks</p>