How to use temp

Comprehensive temp code examples:

How to use temp.openSync:

313
314
315
316
317
318
319
320
321
  });
});

describe('when an editor is saved and the project has no path', () => {
  it("sets the project's path to the saved file's parent directory", () => {
    const tempFile = temp.openSync().path;
    atom.project.setPaths([]);
    expect(atom.project.getPaths()[0]).toBeUndefined();
    let editor = null;

How to use temp.createWriteStream:

394
395
396
397
398
399
400
401
402
403
404
  }
};


exports.writeStringToFile = function(stringContent) {
  return Q.Promise(function(resolve, reject) {
    const stream = temp.createWriteStream();
    stream.write(stringContent);
    stream.on('finish', function() {
      return resolve(stream.path);
    });

How to use temp.track:

21
22
23
24
25
26
27
28
29
30
31
32
  'propertyIsEnumerable'
]


describe('mmap-object', function () {
  before(function () {
    temp.track()
    this.dir = temp.mkdirSync('node-shared')
  })


  describe('Writer', function () {

How to use temp.cleanup:

1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
  jsonResultOrFailProm(res, gitPromise(req.body.command, req.body.path)).then(
    emitWorkingTreeChanged.bind(null, req.body.path)
  );
});
app.post(`${exports.pathPrefix}/testing/cleanup`, (req, res) => {
  temp.cleanup((err, cleaned) => {
    logger.info('Cleaned up: ' + JSON.stringify(cleaned));
    res.json({ result: cleaned });
  });
});

How to use temp.open:

180
181
182
183
184
185
186
187
188
189
.on('data', (d) => {
  contents += d.toString();
})
.on('end', () => {
  const ext = path.extname(transformFile);
  temp.open({ prefix: 'jscodeshift', suffix: ext }, (err, info) => {
    if (err) return reject(err);
    fs.write(info.fd, contents, function (err) {
      if (err) return reject(err);
      fs.close(info.fd, function(err) {

How to use temp.mkdir:

41
42
43
44
45
46
47
48
49
50
windowInitializationScript = require.resolve(
  path.join(resourcePath, 'src/initialize-application-window')
);

atomHome = await new Promise((resolve, reject) => {
  temp.mkdir('launch-', (err, rootPath) => {
    if (err) {
      reject(err);
    } else {
      resolve(rootPath);

How to use temp.cleanupSync:

301
302
303
304
305
306
307
308
309
310
  if (options.failOnError && fileCounters.error > 0) {
    process.exit(1);
  }
}
if (usedRemoteScript) {
  temp.cleanupSync();
}
return Object.assign({
  stats: statsCounter,
  timeElapsed: timeElapsed

How to use temp.path:

14
15
16
17
18
19
20
21
22
23
24
25


const { runReadmeGenerator } = require('../index.js');


test('Check basic functionality. First execution', () => {
  // Create empty temp file with 'Parameters' section
  let tempFile = temp.path({ prefix: 'readme-generator'});
  let parametersHeader = "# Example\r\n\n## Parameters";
  fs.writeFileSync(tempFile, parametersHeader);
  // Run readme generator with the test files
  const options = {

How to use temp.mkdirSync:

22
23
24
25
26
27
28
29
30
31
32
33
]


describe('mmap-object', function () {
  before(function () {
    temp.track()
    this.dir = temp.mkdirSync('node-shared')
  })


  describe('Writer', function () {
    beforeEach(function () {