os#tmpdir JavaScript Examples

The following examples show how to use os#tmpdir. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: main.js    From HinataMd with GNU General Public License v3.0 6 votes vote down vote up
function clearTmp() {
  const tmp = [tmpdir(), join(__dirname, './tmp')]
  const filename = []
  tmp.forEach(dirname => readdirSync(dirname).forEach(file => filename.push(join(dirname, file))))
  return filename.map(file => {
    const stats = statSync(file)
    if (stats.isFile() && (Date.now() - stats.mtimeMs >= 1000 * 60 * 3)) return unlinkSync(file) // 3 minutes
    return false
  })
}
Example #2
Source File: owner-cleartmp.js    From HinataMd with GNU General Public License v3.0 6 votes vote down vote up
handler = async (m, { conn, usedPrefix: _p, __dirname, args }) => {

conn.reply(m.chat, 'Succes !', m)

const tmp = [tmpdir(), join(__dirname, '../tmp')]
  const filename = []
  tmp.forEach(dirname => readdirSync(dirname).forEach(file => filename.push(join(dirname, file))))
  return filename.map(file => {
    const stats = statSync(file)
    unlinkSync(file)
})
}
Example #3
Source File: file_mgr.js    From freyr-js with Apache License 2.0 6 votes vote down vote up
export default async function genFile(opts) {
  opts = opts || {};
  if (opts.filename) {
    opts.tmpdir = opts.tmpdir || tmpdir();
    if (!(await exists(opts.tmpdir))) throw new Error('tmpdir does not exist');
    const dir = join(opts.tmpdir, opts.dirname || '.');
    await mkdirp(dir);
    const name = join(dir, opts.filename);
    const fd = await open(name, fs.constants.O_CREAT);
    hookupListeners();
    let closed = false;
    const garbageHandler = () => {
      if (closed) return;
      fs.closeSync(fd);
      closed = true;
      if (!opts.keep) fs.unlinkSync(name);
    };
    removeCallbacks.unshift(garbageHandler);
    return {
      fd,
      name,
      removeCallback: async () => {
        if (closed) return;
        await close(fd);
        closed = true;
        await unlink(name);
        removeCallbacks.splice(removeCallbacks.indexOf(garbageHandler), 1);
      },
    };
  }
  return new Promise((res, rej) =>
    tmp.file(opts, (err, name, fd, removeCallback) => (err ? rej(err) : res({fd, name, removeCallback}))),
  );
}
Example #4
Source File: index.js    From v8-deopt-viewer with MIT License 5 votes vote down vote up
defaultOptions = {
	logFilePath: `${tmpdir()}/v8-deopt-generate-log/v8.log`,
	browserTimeoutMs: 5000,
}
Example #5
Source File: filesystem.spec.js    From kit with MIT License 5 votes vote down vote up
suite_copy.before.each(() => {
	const temp_dir = mkdtempSync(join(tmpdir(), 'kit-core-filesystem-'));
	source_dir = join(temp_dir, 'source');
	dest_dir = join(temp_dir, 'dest');
	mkdirSync(source_dir);
	mkdirSync(dest_dir);
});