How to use the graceful-fs.writeFileSync function in graceful-fs

To help you get started, we’ve selected a few graceful-fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Mostafa-Samir / zip-local / libs / ZipExport.js View on Github external
var callback = _callback || function () { };

    if (!this.src_unzipped) {
        // generate the zipped buffer
        var buff = this.content.generate({
            type: "nodebuffer",
            compression: this.compressed ? "DEFLATE" : undefined
        });

        var normalized_path = path.normalize(_path);

        // write the new file
        if (!this.save_async) {

            fs.writeFileSync(normalized_path, buff);

        }
        else
            fs.writeFile(normalized_path, buff, function (err) {

                if (err) {
                    callback(err);
                    return;
                }

                //invoke the callback
                callback(null);

            });
    }
    else {
github alan-ai / alan-sdk-reactnative / testtools / node_modules / fs-extra / lib / ensure / file.js View on Github external
function createFileSync (file) {
  let stats
  try {
    stats = fs.statSync(file)
  } catch (e) {}
  if (stats && stats.isFile()) return

  const dir = path.dirname(file)
  if (!fs.existsSync(dir)) {
    mkdir.mkdirsSync(dir)
  }

  fs.writeFileSync(file, '')
}
github eugene1g / font-blast / lib / font-blast / index.js View on Github external
characterSvgs.forEach(function (char) {

            var filename = char.name ? char.name : char.code;
            //If a subset of icons set was requested, ignore any others that are not within the subset
            if (config.icons && config.icons.length &&
                config.icons.indexOf(char.code) == -1 &&
                config.icons.indexOf(filename) == -1) {
                return;
            }
            savedIcons.push(char);
            fs.writeFileSync(path.join(svgDir, filename + '.svg'), char.svg);
        });
        console.info("Saved " + savedIcons.length + " files to " + svgDir);
github nodeshift / license-reporter / lib / file-writer.js View on Github external
function createYaml (options, xmlObject) {
  if (!options.silent) {
    console.log(yaml.stringify(xmlObject, 4));
  }
  if (options.yaml) {
    const fileName = options.yaml.substring(0, options.yaml.length - path.extname(options.yaml).length);
    fs.writeFileSync(path.join(util.licensesDir(), `${fileName}.yaml`), yaml.stringify(xmlObject, 4));
  }
}
github tidys / CocosCreatorPlugins / packages / excel-killer / node_modules / fs-extra / lib / ensure / file.js View on Github external
function createFileSync (file) {
  let stats
  try {
    stats = fs.statSync(file)
  } catch (e) {}
  if (stats && stats.isFile()) return

  const dir = path.dirname(file)
  if (!fs.existsSync(dir)) {
    mkdir.mkdirsSync(dir)
  }

  fs.writeFileSync(file, '')
}
github Kode / khamake / node_modules / fs-extra / lib / ensure / index.js View on Github external
function createFileSync (file) {
  if (fs.existsSync(file)) return

  var dir = path.dirname(file)
  if (!fs.existsSync(dir)) {
    mkdir.mkdirsSync(dir)
  }

  fs.writeFileSync(file, '')
}
github Rich-Harris / sander / index.js View on Github external
fs.readdirSync( src ).forEach( function ( filename ) {
							var srcpath = src + path.sep + filename,
								destpath = dest + path.sep + filename;

							if ( fs.statSync( srcpath ).isDirectory() ) {
								return copydir( srcpath, destpath );
							}

							data = fs.readFileSync( srcpath, readOptions );
							fs.writeFileSync( destpath, data, writeOptions );
						});
					};
github Financial-Times / polyfill-library / polyfills / Intl / update.task.js View on Github external
function writeFileIfChanged (filePath, newFile) {
	if (fs.existsSync(filePath)) {
		var currentFile = fs.readFileSync(filePath);
		var currentFileHash = md5(currentFile);
		var newFileHash = md5(newFile);

		if (newFileHash !== currentFileHash) {
			fs.writeFileSync(filePath, newFile);
		}
  } else {
		fs.writeFileSync(filePath, newFile);
	}
}
github gyselroth / balloon-client-desktop / app / lib / instance.js View on Github external
function persist() {
  if(fs.existsSync(instancesFile)) {
    fs.truncateSync(instancesFile, 0);
  }

  fs.writeFileSync(instancesFile, JSON.stringify(instances, null, 2));
}
github mkg20001 / npm-adblock / hookNpm.js View on Github external
actions.forEach(({name, path}) => {
  try {
    log(path)

    const contents = String(fs.readFileSync(path))
    const patchedContents = patchHook(contents, name)

    if (contents !== patchedContents) {
      fs.writeFileSync(path, patchedContents)
    }
  } catch (_err) {
    if (_err.code === 'EACCES') {
      if (!process.env.ADBLOCK_SUDO && process.platform === 'linux') {
        tryAgainWithSudo = true
      } else {
        err('\n *** Failed patching %s *** \n *** You NEED to run this script as an administrator or otherwise make the file accessible for patching! *** \n', path)
      }
      return
    } else if (_err.code === 'EPERM') {
      if (!process.env.ADBLOCK_SUDO && process.platform === 'linux') {
        tryAgainWithSudo = true
      } else if (!process.env.ADBLOCK_UAC && process.platform === 'win32') {
        tryAgainWithUAC = true
      } else {
        err('\n *** Failed patching %s *** \n *** You NEED to run this script as an administrator or otherwise make the file accessible for patching! *** \n', path)