Write content to file using utf8 encoding

@param {String} filePath
@param {String} content
@param {Function} [callback]
760969
function writeFileUtf8 (filePath, content, callback) {
  // Argument callback defaults to throwError.
  if (typeof callback !== 'function') callback = throwError

  if (typeof content === 'string') {
    fs.writeFile(filePath, content, 'utf8', callback)
  } else {
    throw TypeError(error.contentIsNotString)
  }
}
711368
function(content) {
		if (typeof content != 'string') {
			content = JSON.stringify(content, null, '\t');
		}

		fs.writeFileSync(catalogFile, content);
	}
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
      });
    });
  });
}
1282581
function(file, content, callback) {
			fs.writeFile(file, content, 'ascii', function(err) {
				callback(err ? err : null);
			});
		}
174346
function (data, fragmentKey, cachePath, callback) {
    debug('  write content in file system');
    var basePath =  path.dirname(fragmentKey);
    if (basePath){
      mkdirp.sync(cachePath + '/' + basePath);
    }
    fs.writeFile(cachePath + '/' + fragmentKey, data, function (err) {
      if (err) {
        callback(err);
      } else {
        callback(null, data);
      }
    });
  }
1171908
function LoadFileConfigStrategy (filePath, mustExist, encoding) {
  this.filePath = filePath;
  this.mustExist = mustExist || false;
  this.encoding = encoding || 'utf8';
}
844324
function(file, targetPath) {
		rigger(
			file,
			{ output: targetPath},
			function(error, content) {
				if (error) {
					console.log(error);
					return;
				}
				fs.writeFile(targetPath, content, 'utf8');
			}
		);
	}
1180978
function parseFile(filePath, encoding, callback) {
	return fs.readFile(filePath, encoding, function(err, fileString) {
		if (err) {
			return callback(err);
		}

		fileString = expandIncludes(fileString, path.dirname(filePath));

		return parse(fileString, callback);
	});
}
397062
function writeFile(path,content) {
    return when.promise(function(resolve,reject) {
        var stream = fs.createWriteStream(path);
        stream.on('open',function(fd) {
            stream.end(content,'utf8',function() {
                fs.fsync(fd,resolve);
            });
        });
        stream.on('error',function(err) {
            reject(err);
        });
    });
}
1330807
function replace_content(fullpath) {
	var source = fs.readFileSync(fullpath, 'utf8');
	var regex = /(require\s*\(\s*['"]alloy\/underscore['"]\s*\))._/g
	var test = regex.test(source);
	if(test) {
		logger.trace("Fixing file: " + fullpath);
		source = source.replace(regex, "$1");
		fs.writeFileSync(fullpath, source);
	}
}
838683
function(path, callback) {
		fs.readFile(path, 'utf8', function(err, data) {
			if (!err) {
				marked.setOptions({
					gfm: true,
					tables: true,
					breaks: false,
					pedantic: false,
					sanitize: true,
					smartLists: true,
					smartypants: false,
					langPrefix: 'language-',
					highlight: function(code, lang) {
						return code;
					}
				});
				data = marked(data);
			}
			callback(err, data);
		});
	}
826039
function writeFile(ngindoxObj, encoding, callback) {
	fs.writeFile(filePath, fileString, encoding, function(err) {
		if (err) {
			return callback(err);
		}
		return write(ngindoxObj, callback);
	});
}
47550
function processFile(rootPath, log) {
  return (file, callback) => {
    const filePath = path.join(rootPath, file.path);
    const writeMode = isStream(file.data) ? WriteMode.STREAM : WriteMode.UTF8;
    write(filePath, file.data, writeMode, (error) => {
      if (log === true && !error) {
        console.log(`Successfully wrote file '${file.path}'`);
      }

      async.nextTick(callback, error, file);
    });
  };
}
1112471
function readFileContent(fileName){
    try{
        return(fs.readFileSync(fileName , "utf-8"));
    }catch(e){
        console.log("---readFileContent-- Error reading file "+fileName);
        console.log(e);
        return null;
    }
}
1361905
def set_file_encoding(self, path, encoding):
        
        try:
            map = json.loads(self._settings.value('cachedFileEncodings'))
        except TypeError:
            map = {}
        map[path] = encoding
        self._settings.setValue('cachedFileEncodings', json.dumps(map))
43244
def write_file(path, content, mode=None, encoding='utf-8'):
    '''  '''
    if not mode:
        if isinstance(content, bytes):
            mode = 'wb'
        else:
            mode = 'wt'
    if not path:
        raise ValueError("Output path is invalid")
    else:
        getLogger().debug("Writing content to {}".format(path))
        # convert content to string when writing text data
        if mode in ('w', 'wt') and not isinstance(content, str):
            content = to_string(content)
        elif mode == 'wb':
            # content needs to be encoded as bytes
            if not isinstance(content, str):
                content = to_string(content).encode(encoding)
            else:
                content = content.encode(encoding)
        if str(path).endswith('.gz'):
            with gzip.open(path, mode) as outfile:
                outfile.write(content)
        else:
            with open(path, mode=mode) as outfile:
                outfile.write(content)
511759
function writeJSConfigFile(config, filePath) {
    debug(`Writing JS config file: ${filePath}`);

    let contentToWrite;
    const stringifiedContent = `module.exports = ${stringify(config, { cmp: sortByKey, space: 4 })};`;

    try {
        const CLIEngine = require("../cli-engine");
        const linter = new CLIEngine({
            baseConfig: config,
            fix: true,
            useEslintrc: false
        });
        const report = linter.executeOnText(stringifiedContent);

        contentToWrite = report.results[0].output || stringifiedContent;
    } catch (e) {
        debug("Error linting JavaScript config file, writing unlinted version");
        const errorMessage = e.message;

        contentToWrite = stringifiedContent;
        e.message = "An error occurred while generating your JavaScript config file. ";
        e.message += "A config file was still generated, but the config file itself may not follow your linting rules.";
        e.message += `\nError: ${errorMessage}`;
        throw e;
    } finally {
        fs.writeFileSync(filePath, contentToWrite, "utf8");
    }
}