code: function writeFile(filepath, data, options, callback) {
    if (typeof options === 'function') {
      callback = options;
      options = {};
    }
  
    if (!Buffer.isBuffer(data)) {
      return callback(new TypeError('Data must be a Buffer'));
    }
  
    if (!options) {
      options = {};
    }
  
    // Default the same as node
    var mode = options.mode || constants.DEFAULT_FILE_MODE;
    var flags = options.flags || 'w';
    var position = APPEND_MODE_REGEXP.test(flags) ? null : 0;
  
    fs.open(filepath, flags, mode, onOpen);
  
    function onOpen(openErr, fd) {
      if (openErr) {
        return onComplete(openErr);
      }
  
      fs.write(fd, data, 0, data.length, position, onComplete);
  
      function onComplete(writeErr) {
        callback(writeErr, fd);
      }
    }
  }
docs: /*
  Custom writeFile implementation because we need access to the
  file descriptor after the write is complete.
  Most of the implementation taken from node core.