How to use the temp.open 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 jedp / persona-yubikey / scripts / awsbox_local / post_create.js View on Github external
function copyConfig(callback) {
  temp.open({}, function(err, tempfile) {
    if (err) throw err;

    var config = {
      // Our keys for signing certificates
      gnomn_public_key: JSON.parse(fs.readFileSync(path.join(__dirname, '../../sekret/key.publickey'))),
      gnomn_private_key: JSON.parse(fs.readFileSync(path.join(__dirname, '../../sekret/key.secretkey'))),

      // Yubico client api keys
      yubico_client_id: getenv('YUBICO_CLIENT_ID'),
      yubico_secret_key: getenv('YUBICO_SECRET_KEY')
    };

    fs.writeFileSync(tempfile.path, JSON.stringify(config), 'utf8');
    var dest = 'app@'+getenv('AWS_IP_ADDRESS')+':'+CONFIG_FILE

    console.log("Copying config");
github toshok / echojs / test / tester.js View on Github external
function checkStdout(test_name, elapsed, cb) {
    if (stdouts[test_name] != expected_stdouts[test_name]) {
        temp.open("ejstest-received", function (err, info) {
            fs.writeSync(info.fd, stdouts[test_name]);
            fs.close(info.fd, function (err) {
                exec("/usr/bin/diff -u " + expected_names[test_name] + " " + info.path, function (err, stdout) {
                    testFailed(test_name, "stdout doesn't match", elapsed, stdout);
                    cb();
                });
            });
        });
    }
    else {
        if (xfails[test_name]) {
            testUnexpectedPass(test_name, elapsed);
        }
        else {
            writeOutput(test_name, pass_str, elapsed);
        }
github DefinitelyTyped / DefinitelyTyped / types / temp / temp-tests.ts View on Github external
function testOpen() {
    temp.open({ dir: "tempDir", prefix: "pref", suffix: "suff" }, (err, result) => {
        const { path, fd } = result;
        path.length;
        fd.toPrecision(5);
    });

    temp.open("strPrefix", (err, result) => {
        const { path, fd } = result;
        path.length;
        fd.toPrecision(5);
    });
}
github deyunanhai / tupai.js / scripts / nodejs / templates.js View on Github external
onStdoutData: options.onStdoutData,
            onStderrData: options.onStderrData,
            end: function(code) {
                end && end(code, url);
            }
        });
    }

    if(needMinify) {
        var html = require('html-minifier').minify(data.toString(), {
            removeComments: true,
            collapseWhitespace: true,
            useShortDoctype: true
        });

        temp.open({suffix: '.html'}, function(err, info) {
            if(err) {
                console.log('an error occured:', err);
                return;
            }
            fs.writeSync(info.fd, html);
            fs.close(info.fd, function(err) {
                if(err) {
                    console.log('an error occured:', err);
                    return;
                }
                var tempUrl = info.path;
                compile(tempUrl, function(code) {
                    fs.unlink(tempUrl);
                    options && options.end && options.end(code, url);
                });
            });
github glejeune / node-graphviz / lib / graphviz.js View on Github external
exports.parse = function(file_or_script, callback, errback) {
  if (fsExt.exist(file_or_script)) {
    _parse(file_or_script, callback, errback);
  } else {
    temp.open('node-graphviz', function(err, info) {
      if (err) {
        return errback(err);
      }
      fs.write(info.fd, file_or_script, function(err) {
        if (err) {
          return errback(err);
        }
        fs.close(info.fd, function(err) {
          if (err) {
            return errback(err);
          }
          _parse(info.path, callback, errback);
        });
      });
    });
  }
github joeferner / node-tshark / lib / pcapConverter.js View on Github external
function getOrOpenTempFile(callback) {
    if (tempFile) {
      return callback(null, tempFile);
    } else {
      if (self.opts.tempDir) {
        temp.dir = self.opts.tempDir;
      }
      return temp.open(TEMP_PREFIX, function(err, newTempFile) {
        if (err) {
          return callback(err);
        }
        tempFile = newTempFile;
        tempFile.packetCount = 0;
        tempFile.capturedLength = 0;
        tempFile.createdOn = Date.now();

        var globalHeaderBuffer = createGlobalHeader(globalHeader);
        return fs.write(tempFile.fd, globalHeaderBuffer, 0, globalHeaderBuffer.length, null, function(err) {
          if (err) {
            return callback(err);
          }
          return callback(null, tempFile);
        });
      });
github shd101wyy / mume / out / src / utility.js View on Github external
return new Promise((resolve, reject) => {
        temp.open(options, function (error, info) {
            if (error)
                return reject(error.toString());
            return resolve(info);
        });
    });
}
github mozilla / shumway / src / shell / numbers.js View on Github external
function patchTest(file, text, next) {
  if (fs.existsSync(file + ".diff")) {
    temp.open("out", function (err, info) {
      fs.writeSync(info.fd, text);
      var command = "patch " + info.path + " " + file + ".diff";
      exec(command, {}, function (error, stdout, stderr) {
        next(readFile(info.path).toString());
      });
    });
  } else {
    next(text);
  }
}
github crucialfelix / supercolliderjs / packages / lang / src / sclang.ts View on Github external
return new Promise((resolve, reject) => {
      temp.open("sclang-conf", function(err, info) {
        if (err) {
          return reject(err);
        }

        fs.write(info.fd, str, err2 => {
          if (err2) {
            reject(err2);
          } else {
            fs.close(info.fd, err3 => {
              if (err3) {
                reject(err3);
              } else {
                resolve(info.path);
              }
            });
          }