How to use the temp.openSync function in temp

To help you get started, we’ve selected a few temp 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 nwjs-community / nw-builder / test / utils.js View on Github external
test('mergeFiles', function (t) {
    t.plan(isWindows ? 1 : 2);

    var releasefile = temp.openSync();
    fs.writeFileSync(releasefile.path, 'A');

    var zipFile = temp.openSync();
    fs.writeFileSync(zipFile.path, 'B');

    utils.mergeFiles(releasefile.path, zipFile.path, '0755').then(function() {
        var contents = fs.readFileSync(releasefile.path);
        var stats    = fs.lstatSync(releasefile.path);
        t.equal(contents.toString(), 'AB', 'merge two files');

        if(!isWindows) {
            t.equal(stats.mode.toString(8), '100755', 'fix the permission'); // DOES NOT WORK ON WINDOWS
        }
    });

});
github DavyJonesLocker / ember-suave / lib / jscsrc-builder.js View on Github external
jscsConfig = mergeConfigs(userConfig || {}, suaveConfig);

  // Project custom rules
  projectRoot = project && project.root || process.cwd();
  projectRules = jscsConfig.additionalRules || [];
  jscsConfig.additionalRules = projectRules.map(function(rulePath) {
    return path.resolve(projectRoot, rulePath);
  });

  // Addon custom rules unless userConfig already included them
  if (!hasEmberSuaveCustomRules(jscsConfig.additionalRules)) {
    customRulePath = path.join(__dirname, 'rules');
    jscsConfig.additionalRules.push(path.join(customRulePath, '*.js'));
  }

  info = temp.openSync('ember-suave');
  fs.writeSync(info.fd, JSON.stringify(jscsConfig));
  fs.closeSync(info.fd);

  return info.path;
};
github lodash-archive / grunt-lodash / lib / builder.js View on Github external
var lodashBuilder = require(lodashPath.replace('dist/lodash.js', 'build.js'));
      var lodashTarget = _;

      // check if we should use a different lodash version
      if (options.config.src) {
        try {
          grunt.file.read(options.config.src + '/build.js');
          lodashPath = options.config.src + '/lodash.js';
          lodashTarget = require(options.config.src + '/lodash.js');
        } catch (e) {
          contentCb(new Transport('error', 'Could not load given lodash version at "' + options.config.src + '"'), options);
          return null;
        }
      }

      var temporaryLodash = temp.openSync('lodash');
      var mappedConfig = ['--silent', '--output', temporaryLodash.path];
      // load lodash version
      var version = lodashTarget.VERSION;
      // check lodash version
      if (semver.gte(version, '0.7.0')) {
        // check for debug or minified output
        if ((options.debug === true || options.minify === false) && semver.gte(version, '0.7.0')) {
          mappedConfig.push('--debug');
        }

        // parse arguments
        var args = exports.parseArgs(options.config, mappedConfig);
        // launch lodash builder
        lodashBuilder(args, function (output) {
          var outputSize = 0;
          fs.unlink(temporaryLodash.path);
github facebook / jscodeshift / utils / testUtils.js View on Github external
function createTempFileWith(content, filename, extension) {
  const info = temp.openSync({ suffix: extension });
  let filePath = info.path;
  fs.writeSync(info.fd, content);
  fs.closeSync(info.fd);
  if (filename) {
    filePath = renameFileTo(filePath, filename);
  }
  return filePath;
}
exports.createTempFileWith = createTempFileWith;
github erelsgl / limdu / classifiers / multilabel / kNN.js View on Github external
classify: function(sample, explain) {

		this.learnFile = temp.openSync({prefix:"kNN-", suffix:".learn.arff"});
		this.testFile = temp.openSync({prefix:"kNN-", suffix:".test.arff"});

		if (!(this.distanceWeightening in this.distancemap))
		{
			console.error("distanceWeightening not in distancemap")
			process.exit(0)
		}

		this.writeData(this.dataset, 0, this.learnFile)

		var dataset = [{'input': sample, 'output': '?'}]
		this.writeData(dataset, 0, this.testFile)

		var command = "java weka.classifiers.lazy.IBk "+
		"-t " + this.learnFile.path + " -T " + this.testFile.path + " " + this.distancemap[this.distanceWeightening] + " -K 1 -W 0 "+
		"-A \"weka.core.neighboursearch.LinearNNSearch -A \\\"weka.core." + this.distanceFunction + " -R first-last\\\"\" -p 0"
github viddo / atom-textual-velocity / spec / darwin-spec.js View on Github external
beforeEach(function () {
    temp.track()
    const f = temp.openSync('file-with-tags')
    path = f.path
    callbackSpy = jasmine.createSpy('callback')
  })
github psirenny / node-google-speech-api / index.js View on Github external
queue.drain = function () {
    if (!finishedReadingFile) return;
    callback(null, queue.results);
  };

  queue.events.on('error', function (err) {
    queue.kill();
    callback(err);
  });

  if (opts.file) {
    return reader.open(opts.file);
  }

  var file = temp.openSync().path;
  var writeStream = fs.createWriteStream(file);

  reader.on('end', function () {
    fs.unlink(file);
  });

  reader.on('error', function () {
    fs.unlink(file);
  });

  queue.events.on('error', function () {
    fs.unlink(file);
  });

  writeStream.on('end', function () {
    reader.open(file);
github cambecc / earth / server / gfs-update.js View on Github external
function createTempSync(options) {
    var tempFile = temp.openSync(options);
    fs.closeSync(tempFile.fd);
    return tempFile.path;
}
github atom / superstring / script / profile-command.js View on Github external
function profileCommand (command, containingFunctionName, callback) {
  const dtraceOutputFile = temp.openSync({prefix: 'dtrace.out'});
  const flamegraphFile = temp.openSync({prefix: 'flamegraph', suffix: '.html'});
  fs.chmodSync(flamegraphFile.path, '755');

  const dtraceProcess = spawn("dtrace", [
    "-x", "ustackframes=100",
    "-n", "profile-2000 /pid == $target/ { @num[ustack()] = count(); }",
    "-c", command
  ], {
    stdio: ['ignore', dtraceOutputFile.fd, process.stderr]
  });

  dtraceProcess.on('close', function(code) {
    if (code !== 0) {
      return callback(code);
    }
github cambecc / earth / server / oscar-update.js View on Github external
function createTempSync(options) {
    var tempFile = temp.openSync(options);
    fs.closeSync(tempFile.fd);
    return tempFile.path;
}