8000 gemini/lib/temp.js at v4.18.2 · gemini-testing/gemini · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Latest commit

 

History

History
54 lines (44 loc) · 1.07 KB

temp.js

File metadata and controls

54 lines (44 loc) · 1.07 KB
'use strict';
var inherit = require('inherit'),
temp = require('temp'),
path = require('path'),
_ = require('lodash');
temp.track();
var Temp = inherit({
__constructor: function(dir, opts) {
opts = opts || {};
this._tempDir = opts.attach
? dir
: temp.mkdirSync({
dir: dir && path.resolve(dir),
prefix: '.gemini.tmp.'
});
},
path: function(opts) {
return temp.path(_.extend(opts || {}, {
dir: this._tempDir
}));
},
serialize: function() {
return {dir: this._tempDir};
}
});
var tempInstance;
module.exports = {
init: function(dir) {
if (!tempInstance) {
tempInstance = new Temp(dir);
}
},
attach: function(serializedTemp) {
if (!tempInstance) {
tempInstance = new Temp(serializedTemp.dir, {attach: true});
}
},
path: function(opts) {
return tempInstance.path(opts);
},
serialize: function() {
return tempInstance.serialize();
}
};
0