Writes a file to disk.

@param {string} filePath The file path to write to.
@param {string} contents A UTF-8 encoded string of the file contents.
@return {Promise<void>} Resolves when the file has been written successfully.
174348
function writeFile(filePath, contents) {
  return new Promise((resolve, reject) => {
    fs.writeFile(filePath, contents, 'utf-8', (err, file) => {
      err ? reject(err) : resolve();
    })
  });
}
326788
function writeFile(pathToFile, content, verbose) {
  const directory = path.dirname(pathToFile);

  // Create directory if it doesn't exist
  if (!fs.existsSync(directory)) {
    fs.mkdirSync(directory);
  }

  // Try to write file to disk to the given location
  fs.writeFile(pathToFile, content, { flag: 'w' }, (error) => {
    if (error) {
      throw new Error(error);
    }

    // Log success message to the console if in verbose mode only
    if (verbose) {
      const successMessage = `\nVersion file written to ${chalk.green(pathToFile)}`;

      console.log(successMessage);
    }
  });
}
978893
public static void write(String path, String str) throws IOException {
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
				path), "utf8"));
		out.append(str);
		out.close();		
	}
962796
def write_file(self, path, contents):
		
		path = self._get_dist_path(path)
		if not os.path.isdir(os.path.dirname(path)):
			os.makedirs(os.path.dirname(path))
		if isinstance(contents, bytes):
			mode = 'wb+'
		else:
			mode = 'w'
		with open(path, mode) as file:
			file.write(contents)
1036952
function handleFile(fs, path, res) {
  var contentType = mime.lookup(path);
  var encoding = mime.charsets.lookup(contentType) === "UTF-8" ? "utf8" : null;

  fs.readFile(path, {encoding: encoding}, function(err, data) {
    if(err) {
      log.error(err, 'Unable to read file path `%s`', path);
      handle404(path, res);
      return;
    }

    write(data, contentType, res);
  });
}
450640
async function write(path, data) {
  if (!path) throw new Error('No path is given.')
  const er = erotic(true)
  const ws = createWriteStream(path)
  await new Promise((r, j) => {
    ws
      .on('error', (e) => {
        const err = er(e)
        j(err)
      })
      .on('close', r)
      .end(data)
  })
}
552295
function write (filename, content) {
  const json = JSON.stringify(content, (key, value) => value === undefined ? null : value)
  fs.writeFileSync(filename, json)
  return json
}
1106305
function (filePath, encode) {
        encode = encode || 'utf-8';

        if (this.isFileSync(filePath)) {
            var raw = fs.readFileSync(filePath, encode);
            var exports = {};
            var context = {
                process: process,
                require: function(name) {
                    var module;
                    try {
                        module = require((function (_module) {
                            if (_module.charAt(0) !== '.') {
                                return _module;
                            }
                            return path.resolve(path.dirname(filePath), _module);
                        }(name)));
                    } catch (e) {
                        throw e;
                    }
                    return module;
                },
                __filename: __filename,
                __dirname: __dirname,
                console: console,
                module: {
                    exports: exports
                },
                exports: exports
            };

            try {
                return vm.runInNewContext(raw, context);
            } catch (e) {
                throw e;
            }
        }
        return {};
    }
244437
function(/**string*/ outDir, /**string*/ fileName, /**string*/ content) {
		fs.writeFileSync(outDir + "/" + fileName, content, IO.encoding);
	}
1022022
function write(config, filePath) {
    switch (path.extname(filePath)) {
        case ".js":
            writeJSConfigFile(config, filePath);
            break;

        case ".json":
            writeJSONConfigFile(config, filePath);
            break;

        case ".yaml":
        case ".yml":
            writeYAMLConfigFile(config, filePath);
            break;

        default:
            throw new Error("Can't write to unknown file type.");
    }
}
1242375
public function write($filePath, $contents, $mode = 'wb')
    {
        if (false !== ($fp = $this->create($filePath, $mode))) {
            flock($fp, LOCK_EX);

            for ($result = $written = 0, $length = strlen($contents); $written < $length; $written += $result) {
                if (($result = fwrite($fp, substr($contents, $written))) === false) {
                    break;
                }
            }

            flock($fp, LOCK_UN);
            fclose($fp);

            return is_int($result);
        }

        return false;
    }
9574
public void writeFile(String filePath, byte[] data) throws IOException
   {
      Object lock = retrieveLock(filePath);      
      synchronized (lock) 
      {
         IO.writeFile(filePath, data);
      }
   }
727244
function write(file, text='', encoding='utf-8') {
	if (file && file.file) {
		let pathFile = file.path ? file.path + '/' + file.file : file.file;
		return write(pathFile, file.text, file.encoding)
	}else{
		mkdir(file);
		fs.writeFileSync(file, text, encoding);
	}
}
887374
function (file, content, charset, callback) {
    try {
        if (!file) {
            return;
        }
        charset = (charset || 'utf-8').toLowerCase();
        if (charset !== 'utf-8') {
            content = require('iconv-lite').encode(content + '\r\n', charset);
        }
        callback.call(this, file, content);
    } catch (ex) {
        throw util.format('cant write file [%s]%s for %s', charset, file, ex);
    }
}
219067
function promiseReadFile(path, encoding = 'utf-8') {
  return new Promise((resolve, reject) => {
    fs.readFile(path, encoding, (err, content) => {
      if (err) reject(err);

      resolve({
        path,
        fileName: path.split('/').pop(),
        content
      });
    });
  });
}
85758
function appendToFile(fileContent, filePath) {
  return new Promise((resolve, reject) => {
    fs.appendFile(filePath, fileContent, 'utf8', (err) => {
      if (err) {
        reject(err);
      } else {
        resolve(filePath);
      }
    });
  });
}
1167498
protected function createFile($filePath, $contents)
    {
        $this->createDirectory(dirname($filePath));
        
        if (is_file($filePath)) {
            // if (!$this->opt('force')) {
            $this->output->setDecorated(true);
            $this->output->writeln(sprintf(
                "<comment>file exists  <cyan>%s</cyan></comment>",
                $this->prettyPath($filePath)
            ));
                // return;
            // } else {
                // $this->output->writeln(sprintf(
                    // "<comment>overwriten  <cyan>%s</cyan></comment>",
                    // $filePath
                // ));
            // }
        } else {
            $this->output->writeln(sprintf(
                "<info>create  <cyan>%s</cyan></info>",
                $this->prettyPath($filePath)
            ));
            file_put_contents($filePath, $contents);
        }
        
    }