function performFileSave(step, task, results) {
  var options = step.options ? xcode(step.options, true) : {};

  resolveFuture(options, results);
  options._id = options._id || dbUtils.generateId();

  step.options = options;
  step.dataStore = [{_id: options._id}];

  return updateState(task, step.index, PENDING).then(function () {
    return new Promise(function (resolve, reject) {
      var conn = mongoose.connection;
      var gfs = Grid(conn.db);
      var writeStream = gfs.createWriteStream(options);

      writeStream.on("close", function (file) {
        results.push(file);

        resolve(results);
      });

      writeStream.on("error", reject);

      fs.createReadStream(step.data.file_path).pipe(writeStream);

    }).then(function (results) {
      return updateState(task, step.index, DONE, results);
    });
  });
}
This function handles the file save step.

@param step the file save step
@param task the task which step belongs to
@param results array of results from previous operations

@returns {Promise|*}