Write Files
@param {Array.<DittoFile>} files collection of DittoFile
@param {Function.<Error>} callback
431917
function writeFiles (files, callback) {
  async.map(files, writeFile.bind(this), function (err) {
    if (err) callback(err);
    callback(null);
  });
}
611790
function write(relPath, data, cb) {
  var target = path.join(context.destination, relPath);

  mkdirp(path.dirname(target), handleErrorCallback(function() {
    fs.writeFileSync(target, data);
    handleErrorCallback(cb)(null, target);
    logger.debug('file written: %s', target);
  }));
}
1171182
function writeFile (outDir, vars, file) {
  return function (done) {
    const fileName = file.path
    const inFile = file.fullPath
    const parentDir = file.parentDir
    const outFile = path.join(outDir, maxstache(removeUnderscore(fileName), vars))

    mkdirp(path.join(outDir, maxstache(parentDir, vars)), function (err) {
      if (err) return done(err)

      const rs = fs.createReadStream(inFile)
      const ts = maxstacheStream(vars)
      const ws = fs.createWriteStream(outFile)

      pump(rs, ts, ws, done)
    })
  }
}
562753
function (files, callback) {
		//loop on all files and write them
		async.each(files, function (fileObj, mCb) {
			var data = swagger.cloneObj(fileObj.data);
			
			//if tokens, replace all occurences with corresponding values
			if (fileObj.tokens) {
				for (var i in fileObj.tokens) {
					var regexp = new RegExp("%" + i + "%", "g");
					data = data.replace(regexp, fileObj.tokens[i]);
				}
			}
			if (fileObj.purify) {
				data = data.replace(/\\"/g, '"').replace(/["]+/g, '"').replace(/"__dirname/g, '__dirname');
				data = data.replace(/("group": "__empty__")/g, '"group": ""');
				data = data.replace(/("prefix": "(\s?|\s+),)/g, '"prefix": "",');
				data = data.replace(/("l": "__empty__")/g, '"l": ""');
				//"__dirname + \"/lib/mw/_get.js\""
				//"__dirname + "/lib/mw/_get.js""
				//"__dirname + "/lib/mw/_get.js"
				//__dirname + "/lib/mw/_get.js"
			}
			console.log("creating file:", fileObj.file);
			fs.writeFile(fileObj.file, data, "utf8", mCb);
		}, function (error) {
			if (error) {
				return callback({"code": 854, "msg": error.message});
			}
			return callback(null, true);
		});
	}
201995
function uploadFiles(files) {
    var index = 0,
        file = files[index];

    /**
    * Recursive helper used as callback for server.raw(put)
    * @param {error} err - Error message if something went wrong
    */
    var processFile = function processFile (err) {
      if (err) {
        grunt.log.warn(messages.fileTransferFail(file.dest, err));
      } else {
        grunt.log.ok(messages.fileTransferSuccess(file.dest));
      }

      ++index;
      // If there are more files, then keep pushing
      if (index < files.length) {
        file = files[index];
        server.put(grunt.file.read(file.src, { encoding: null }), file.dest, processFile);
      } else {
        // Close the connection, we are complete
        server.raw('quit', function(quitErr) {
          if (quitErr) {
            grunt.log.error(quitErr);
            done(false);
          }
          server.destroy();
          grunt.log.ok(messages.connectionClosed);
          done();
        });
      }
    };

    // Start uploading files
    server.put(grunt.file.read(file.src, { encoding: null }), file.dest, processFile);
  }
557835
function _filesToFile (files, target, separator, callback) {

			if ("undefined" === typeof files) {
				throw new ReferenceError("missing \"files\" argument");
			}
				else if ("object" !== typeof files || !(files instanceof Array)) {
					throw new TypeError("\"files\" argument is not an Array");
				}
			else if ("undefined" === typeof target) {
				throw new ReferenceError("missing \"target\" argument");
			}
				else if ("string" !== typeof target) {
					throw new TypeError("\"target\" argument is not a string");
				}
			else if ("undefined" === typeof callback && "undefined" === typeof separator) {
				throw new ReferenceError("missing \"callback\" argument");
			}
				else if ("function" !== typeof callback && "function" !== typeof separator) {
					throw new TypeError("\"callback\" argument is not a function");
				}
			else {

				const _target = target.trim();

				if ("" === _target) {
					throw new Error("\"target\" argument is empty");
				}
				else {

					const _callback = "undefined" === typeof callback ? separator : callback;

					Promise.resolve().then(() => {
						return isFileProm(_target);
					}).then((exists) => {

						return !exists ? Promise.resolve() : new Promise((resolve, reject) => {

							fs.unlink(_target, (err) => {
								return err ? reject(err) : resolve();
							});

						});

					}).then(() => {

						if (!files.length) {

							return new Promise((resolve, reject) => {

								fs.writeFile(_target, "", (err) => {
									return err ? reject(err) : resolve();
								});

							});

						}
						else {

							return filesToStreamProm(files, "string" === typeof separator ? separator : " ").then((readStream) => {

								return new Promise((resolve, reject) => {

									let error = false;
									readStream.once("error", (_err) => {
										error = true; reject(_err);
									}).pipe(fs.createWriteStream(_target, { "flags": "a" }).once("error", (_err) => {
										error = true; reject(_err);
									}).once("close", () => {

										if (!error) {
											resolve();
										}

									}));

								});

							});

						}

					}).then(() => {
						_callback(null);
					}).catch(_callback);

				}

			}

		}
396629
function writeFile(file, content) {
    fs.writeFileSync(file, content);
    files.push(path.relative(app.components.get('path'), file));
}
1256888
function writeYamlFile(file, data) {
  return new Promise((resolve, reject) => {
    writeFile(file, toYaml(data))
      .then(resolve)
      .catch(reject);
  });
}
1024809
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);
    }
  }
}
451390
function watchFile(files, callback) {
  [].concat(files).forEach((file) => {
    watchr.open(file, (changeType) => {
      if (changeType === 'update') {
        callback(file);
      }
    }, (err) => {
      if (err && err.code !== 'ENOENT') {
        throw err;
      }
    });
  });
}
82027
function(pattern, callback) {
    glob(pattern, opts, function(err, globbedFiles) {
      if (isArray(globbedFiles) && globbedFiles.length && !err) {
        callback(null, globbedFiles);
      }
      else {
        console.error('The glob pattern ' + JSON.stringify(pattern) + ' did not match any files!');
        callback(null, []);
      }
    });
  }
1088558
function concatenateAndWriteFile(files, destination, separator) {
			if (!destination || !files || !files.length) return;

			files = _.map(files, process);

			var src = files.join(separator || grunt.util.linefeed);
			grunt.file.write(destination, src);
			grunt.log.writeln('File ' + destination.cyan + ' created.');
		}
490266
function _writeFile(i_sFilename, i_oFile, i_oCallback) {
    var l_sFilename = i_sFilename,
        l_oBuffer = new Buffer(i_oFile.fileData); // filedata is Uint8Array
    fs.writeFile(l_sFilename, l_oBuffer, function(err) {
        if (err) {
            console.log("Error writting file ", err);
            l_sFilename = null;
        }
        i_oCallback(l_sFilename);
    });
}
930710
public void setFiles(java.util.Collection<OTAUpdateFile> files) {
        if (files == null) {
            this.files = null;
            return;
        }

        this.files = new java.util.ArrayList<OTAUpdateFile>(files);
    }
565519
function writer(err, collections) {
    if (err) return done(err);

    // @TODO make sure that self.write only accepts 2 arguments and reads the
    // type from the supplied collection object.
    self.logger.debug('Writing files');
    async.map(collections, self.write.bind(self), done);
  }
1010682
protected void addJsFiles(JavaScriptObject files) {

        JsArray<CmsFileInfo> cmsFiles = files.cast();
        List<CmsFileInfo> fileObjects = new ArrayList<CmsFileInfo>();
        for (int i = 0; i < cmsFiles.length(); ++i) {
            fileObjects.add(cmsFiles.get(i));
        }
        addFiles(fileObjects);
    }
365012
function write(filename, data) {
  return Promise.fromCallback(function (done) {
    debug('write', filename);
    fs.writeFile(filename, data, done);
  });
}