tmp.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. /*!
  2. * Tmp
  3. *
  4. * Copyright (c) 2011-2017 KARASZI Istvan <github@spam.raszi.hu>
  5. *
  6. * MIT Licensed
  7. */
  8. /*
  9. * Module dependencies.
  10. */
  11. const fs = require('fs');
  12. const os = require('os');
  13. const path = require('path');
  14. const crypto = require('crypto');
  15. const _c = fs.constants && os.constants ?
  16. { fs: fs.constants, os: os.constants } :
  17. process.binding('constants');
  18. const rimraf = require('rimraf');
  19. /*
  20. * The working inner variables.
  21. */
  22. const
  23. // the random characters to choose from
  24. RANDOM_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
  25. TEMPLATE_PATTERN = /XXXXXX/,
  26. DEFAULT_TRIES = 3,
  27. CREATE_FLAGS = (_c.O_CREAT || _c.fs.O_CREAT) | (_c.O_EXCL || _c.fs.O_EXCL) | (_c.O_RDWR || _c.fs.O_RDWR),
  28. EBADF = _c.EBADF || _c.os.errno.EBADF,
  29. ENOENT = _c.ENOENT || _c.os.errno.ENOENT,
  30. DIR_MODE = 448 /* 0o700 */,
  31. FILE_MODE = 384 /* 0o600 */,
  32. EXIT = 'exit',
  33. SIGINT = 'SIGINT',
  34. // this will hold the objects need to be removed on exit
  35. _removeObjects = [];
  36. var
  37. _gracefulCleanup = false;
  38. /**
  39. * Random name generator based on crypto.
  40. * Adapted from http://blog.tompawlak.org/how-to-generate-random-values-nodejs-javascript
  41. *
  42. * @param {number} howMany
  43. * @returns {string} the generated random name
  44. * @private
  45. */
  46. function _randomChars(howMany) {
  47. var
  48. value = [],
  49. rnd = null;
  50. // make sure that we do not fail because we ran out of entropy
  51. try {
  52. rnd = crypto.randomBytes(howMany);
  53. } catch (e) {
  54. rnd = crypto.pseudoRandomBytes(howMany);
  55. }
  56. for (var i = 0; i < howMany; i++) {
  57. value.push(RANDOM_CHARS[rnd[i] % RANDOM_CHARS.length]);
  58. }
  59. return value.join('');
  60. }
  61. /**
  62. * Checks whether the `obj` parameter is defined or not.
  63. *
  64. * @param {Object} obj
  65. * @returns {boolean} true if the object is undefined
  66. * @private
  67. */
  68. function _isUndefined(obj) {
  69. return typeof obj === 'undefined';
  70. }
  71. /**
  72. * Parses the function arguments.
  73. *
  74. * This function helps to have optional arguments.
  75. *
  76. * @param {(Options|Function)} options
  77. * @param {Function} callback
  78. * @returns {Array} parsed arguments
  79. * @private
  80. */
  81. function _parseArguments(options, callback) {
  82. /* istanbul ignore else */
  83. if (typeof options === 'function') {
  84. return [{}, options];
  85. }
  86. /* istanbul ignore else */
  87. if (_isUndefined(options)) {
  88. return [{}, callback];
  89. }
  90. return [options, callback];
  91. }
  92. /**
  93. * Generates a new temporary name.
  94. *
  95. * @param {Object} opts
  96. * @returns {string} the new random name according to opts
  97. * @private
  98. */
  99. function _generateTmpName(opts) {
  100. const tmpDir = _getTmpDir();
  101. // fail early on missing tmp dir
  102. if (isBlank(opts.dir) && isBlank(tmpDir)) {
  103. throw new Error('No tmp dir specified');
  104. }
  105. /* istanbul ignore else */
  106. if (!isBlank(opts.name)) {
  107. return path.join(opts.dir || tmpDir, opts.name);
  108. }
  109. // mkstemps like template
  110. // opts.template has already been guarded in tmpName() below
  111. /* istanbul ignore else */
  112. if (opts.template) {
  113. var template = opts.template;
  114. // make sure that we prepend the tmp path if none was given
  115. /* istanbul ignore else */
  116. if (path.basename(template) === template)
  117. template = path.join(opts.dir || tmpDir, template);
  118. return template.replace(TEMPLATE_PATTERN, _randomChars(6));
  119. }
  120. // prefix and postfix
  121. const name = [
  122. (isBlank(opts.prefix) ? 'tmp-' : opts.prefix),
  123. process.pid,
  124. _randomChars(12),
  125. (opts.postfix ? opts.postfix : '')
  126. ].join('');
  127. return path.join(opts.dir || tmpDir, name);
  128. }
  129. /**
  130. * Gets a temporary file name.
  131. *
  132. * @param {(Options|tmpNameCallback)} options options or callback
  133. * @param {?tmpNameCallback} callback the callback function
  134. */
  135. function tmpName(options, callback) {
  136. var
  137. args = _parseArguments(options, callback),
  138. opts = args[0],
  139. cb = args[1],
  140. tries = !isBlank(opts.name) ? 1 : opts.tries || DEFAULT_TRIES;
  141. /* istanbul ignore else */
  142. if (isNaN(tries) || tries < 0)
  143. return cb(new Error('Invalid tries'));
  144. /* istanbul ignore else */
  145. if (opts.template && !opts.template.match(TEMPLATE_PATTERN))
  146. return cb(new Error('Invalid template provided'));
  147. (function _getUniqueName() {
  148. try {
  149. const name = _generateTmpName(opts);
  150. // check whether the path exists then retry if needed
  151. fs.stat(name, function (err) {
  152. /* istanbul ignore else */
  153. if (!err) {
  154. /* istanbul ignore else */
  155. if (tries-- > 0) return _getUniqueName();
  156. return cb(new Error('Could not get a unique tmp filename, max tries reached ' + name));
  157. }
  158. cb(null, name);
  159. });
  160. } catch (err) {
  161. cb(err);
  162. }
  163. }());
  164. }
  165. /**
  166. * Synchronous version of tmpName.
  167. *
  168. * @param {Object} options
  169. * @returns {string} the generated random name
  170. * @throws {Error} if the options are invalid or could not generate a filename
  171. */
  172. function tmpNameSync(options) {
  173. var
  174. args = _parseArguments(options),
  175. opts = args[0],
  176. tries = !isBlank(opts.name) ? 1 : opts.tries || DEFAULT_TRIES;
  177. /* istanbul ignore else */
  178. if (isNaN(tries) || tries < 0)
  179. throw new Error('Invalid tries');
  180. /* istanbul ignore else */
  181. if (opts.template && !opts.template.match(TEMPLATE_PATTERN))
  182. throw new Error('Invalid template provided');
  183. do {
  184. const name = _generateTmpName(opts);
  185. try {
  186. fs.statSync(name);
  187. } catch (e) {
  188. return name;
  189. }
  190. } while (tries-- > 0);
  191. throw new Error('Could not get a unique tmp filename, max tries reached');
  192. }
  193. /**
  194. * Creates and opens a temporary file.
  195. *
  196. * @param {(Options|fileCallback)} options the config options or the callback function
  197. * @param {?fileCallback} callback
  198. */
  199. function file(options, callback) {
  200. var
  201. args = _parseArguments(options, callback),
  202. opts = args[0],
  203. cb = args[1];
  204. // gets a temporary filename
  205. tmpName(opts, function _tmpNameCreated(err, name) {
  206. /* istanbul ignore else */
  207. if (err) return cb(err);
  208. // create and open the file
  209. fs.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err, fd) {
  210. /* istanbul ignore else */
  211. if (err) return cb(err);
  212. if (opts.discardDescriptor) {
  213. return fs.close(fd, function _discardCallback(err) {
  214. /* istanbul ignore else */
  215. if (err) {
  216. // Low probability, and the file exists, so this could be
  217. // ignored. If it isn't we certainly need to unlink the
  218. // file, and if that fails too its error is more
  219. // important.
  220. try {
  221. fs.unlinkSync(name);
  222. } catch (e) {
  223. if (!isENOENT(e)) {
  224. err = e;
  225. }
  226. }
  227. return cb(err);
  228. }
  229. cb(null, name, undefined, _prepareTmpFileRemoveCallback(name, -1, opts));
  230. });
  231. }
  232. /* istanbul ignore else */
  233. if (opts.detachDescriptor) {
  234. return cb(null, name, fd, _prepareTmpFileRemoveCallback(name, -1, opts));
  235. }
  236. cb(null, name, fd, _prepareTmpFileRemoveCallback(name, fd, opts));
  237. });
  238. });
  239. }
  240. /**
  241. * Synchronous version of file.
  242. *
  243. * @param {Options} options
  244. * @returns {FileSyncObject} object consists of name, fd and removeCallback
  245. * @throws {Error} if cannot create a file
  246. */
  247. function fileSync(options) {
  248. var
  249. args = _parseArguments(options),
  250. opts = args[0];
  251. const discardOrDetachDescriptor = opts.discardDescriptor || opts.detachDescriptor;
  252. const name = tmpNameSync(opts);
  253. var fd = fs.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
  254. /* istanbul ignore else */
  255. if (opts.discardDescriptor) {
  256. fs.closeSync(fd);
  257. fd = undefined;
  258. }
  259. return {
  260. name: name,
  261. fd: fd,
  262. removeCallback: _prepareTmpFileRemoveCallback(name, discardOrDetachDescriptor ? -1 : fd, opts)
  263. };
  264. }
  265. /**
  266. * Creates a temporary directory.
  267. *
  268. * @param {(Options|dirCallback)} options the options or the callback function
  269. * @param {?dirCallback} callback
  270. */
  271. function dir(options, callback) {
  272. var
  273. args = _parseArguments(options, callback),
  274. opts = args[0],
  275. cb = args[1];
  276. // gets a temporary filename
  277. tmpName(opts, function _tmpNameCreated(err, name) {
  278. /* istanbul ignore else */
  279. if (err) return cb(err);
  280. // create the directory
  281. fs.mkdir(name, opts.mode || DIR_MODE, function _dirCreated(err) {
  282. /* istanbul ignore else */
  283. if (err) return cb(err);
  284. cb(null, name, _prepareTmpDirRemoveCallback(name, opts));
  285. });
  286. });
  287. }
  288. /**
  289. * Synchronous version of dir.
  290. *
  291. * @param {Options} options
  292. * @returns {DirSyncObject} object consists of name and removeCallback
  293. * @throws {Error} if it cannot create a directory
  294. */
  295. function dirSync(options) {
  296. var
  297. args = _parseArguments(options),
  298. opts = args[0];
  299. const name = tmpNameSync(opts);
  300. fs.mkdirSync(name, opts.mode || DIR_MODE);
  301. return {
  302. name: name,
  303. removeCallback: _prepareTmpDirRemoveCallback(name, opts)
  304. };
  305. }
  306. /**
  307. * Removes files asynchronously.
  308. *
  309. * @param {Object} fdPath
  310. * @param {Function} next
  311. * @private
  312. */
  313. function _removeFileAsync(fdPath, next) {
  314. const _handler = function (err) {
  315. if (err && !isENOENT(err)) {
  316. // reraise any unanticipated error
  317. return next(err);
  318. }
  319. next();
  320. }
  321. if (0 <= fdPath[0])
  322. fs.close(fdPath[0], function (err) {
  323. fs.unlink(fdPath[1], _handler);
  324. });
  325. else fs.unlink(fdPath[1], _handler);
  326. }
  327. /**
  328. * Removes files synchronously.
  329. *
  330. * @param {Object} fdPath
  331. * @private
  332. */
  333. function _removeFileSync(fdPath) {
  334. try {
  335. if (0 <= fdPath[0]) fs.closeSync(fdPath[0]);
  336. } catch (e) {
  337. // reraise any unanticipated error
  338. if (!isEBADF(e) && !isENOENT(e)) throw e;
  339. } finally {
  340. try {
  341. fs.unlinkSync(fdPath[1]);
  342. }
  343. catch (e) {
  344. // reraise any unanticipated error
  345. if (!isENOENT(e)) throw e;
  346. }
  347. }
  348. }
  349. /**
  350. * Prepares the callback for removal of the temporary file.
  351. *
  352. * @param {string} name the path of the file
  353. * @param {number} fd file descriptor
  354. * @param {Object} opts
  355. * @returns {fileCallback}
  356. * @private
  357. */
  358. function _prepareTmpFileRemoveCallback(name, fd, opts) {
  359. const removeCallbackSync = _prepareRemoveCallback(_removeFileSync, [fd, name]);
  360. const removeCallback = _prepareRemoveCallback(_removeFileAsync, [fd, name], removeCallbackSync);
  361. if (!opts.keep) _removeObjects.unshift(removeCallbackSync);
  362. return removeCallback;
  363. }
  364. /**
  365. * Simple wrapper for rimraf.
  366. *
  367. * @param {string} dirPath
  368. * @param {Function} next
  369. * @private
  370. */
  371. function _rimrafRemoveDirWrapper(dirPath, next) {
  372. rimraf(dirPath, next);
  373. }
  374. /**
  375. * Simple wrapper for rimraf.sync.
  376. *
  377. * @param {string} dirPath
  378. * @private
  379. */
  380. function _rimrafRemoveDirSyncWrapper(dirPath, next) {
  381. try {
  382. return next(null, rimraf.sync(dirPath));
  383. } catch (err) {
  384. return next(err);
  385. }
  386. }
  387. /**
  388. * Prepares the callback for removal of the temporary directory.
  389. *
  390. * @param {string} name
  391. * @param {Object} opts
  392. * @returns {Function} the callback
  393. * @private
  394. */
  395. function _prepareTmpDirRemoveCallback(name, opts) {
  396. const removeFunction = opts.unsafeCleanup ? _rimrafRemoveDirWrapper : fs.rmdir.bind(fs);
  397. const removeFunctionSync = opts.unsafeCleanup ? _rimrafRemoveDirSyncWrapper : fs.rmdirSync.bind(fs);
  398. const removeCallbackSync = _prepareRemoveCallback(removeFunctionSync, name);
  399. const removeCallback = _prepareRemoveCallback(removeFunction, name, removeCallbackSync);
  400. if (!opts.keep) _removeObjects.unshift(removeCallbackSync);
  401. return removeCallback;
  402. }
  403. /**
  404. * Creates a guarded function wrapping the removeFunction call.
  405. *
  406. * @param {Function} removeFunction
  407. * @param {Object} arg
  408. * @returns {Function}
  409. * @private
  410. */
  411. function _prepareRemoveCallback(removeFunction, arg, cleanupCallbackSync) {
  412. var called = false;
  413. return function _cleanupCallback(next) {
  414. next = next || function () {};
  415. if (!called) {
  416. const toRemove = cleanupCallbackSync || _cleanupCallback;
  417. const index = _removeObjects.indexOf(toRemove);
  418. /* istanbul ignore else */
  419. if (index >= 0) _removeObjects.splice(index, 1);
  420. called = true;
  421. // sync?
  422. if (removeFunction.length === 1) {
  423. try {
  424. removeFunction(arg);
  425. return next(null);
  426. }
  427. catch (err) {
  428. // if no next is provided and since we are
  429. // in silent cleanup mode on process exit,
  430. // we will ignore the error
  431. return next(err);
  432. }
  433. } else return removeFunction(arg, next);
  434. } else return next(new Error('cleanup callback has already been called'));
  435. };
  436. }
  437. /**
  438. * The garbage collector.
  439. *
  440. * @private
  441. */
  442. function _garbageCollector() {
  443. /* istanbul ignore else */
  444. if (!_gracefulCleanup) return;
  445. // the function being called removes itself from _removeObjects,
  446. // loop until _removeObjects is empty
  447. while (_removeObjects.length) {
  448. try {
  449. _removeObjects[0]();
  450. } catch (e) {
  451. // already removed?
  452. }
  453. }
  454. }
  455. /**
  456. * Helper for testing against EBADF to compensate changes made to Node 7.x under Windows.
  457. */
  458. function isEBADF(error) {
  459. return isExpectedError(error, -EBADF, 'EBADF');
  460. }
  461. /**
  462. * Helper for testing against ENOENT to compensate changes made to Node 7.x under Windows.
  463. */
  464. function isENOENT(error) {
  465. return isExpectedError(error, -ENOENT, 'ENOENT');
  466. }
  467. /**
  468. * Helper to determine whether the expected error code matches the actual code and errno,
  469. * which will differ between the supported node versions.
  470. *
  471. * - Node >= 7.0:
  472. * error.code {string}
  473. * error.errno {string|number} any numerical value will be negated
  474. *
  475. * - Node >= 6.0 < 7.0:
  476. * error.code {string}
  477. * error.errno {number} negated
  478. *
  479. * - Node >= 4.0 < 6.0: introduces SystemError
  480. * error.code {string}
  481. * error.errno {number} negated
  482. *
  483. * - Node >= 0.10 < 4.0:
  484. * error.code {number} negated
  485. * error.errno n/a
  486. */
  487. function isExpectedError(error, code, errno) {
  488. return error.code === code || error.code === errno;
  489. }
  490. /**
  491. * Helper which determines whether a string s is blank, that is undefined, or empty or null.
  492. *
  493. * @private
  494. * @param {string} s
  495. * @returns {Boolean} true whether the string s is blank, false otherwise
  496. */
  497. function isBlank(s) {
  498. return s === null || s === undefined || !s.trim();
  499. }
  500. /**
  501. * Sets the graceful cleanup.
  502. */
  503. function setGracefulCleanup() {
  504. _gracefulCleanup = true;
  505. }
  506. /**
  507. * Returns the currently configured tmp dir from os.tmpdir().
  508. *
  509. * @private
  510. * @returns {string} the currently configured tmp dir
  511. */
  512. function _getTmpDir() {
  513. return os.tmpdir();
  514. }
  515. /**
  516. * If there are multiple different versions of tmp in place, make sure that
  517. * we recognize the old listeners.
  518. *
  519. * @param {Function} listener
  520. * @private
  521. * @returns {Boolean} true whether listener is a legacy listener
  522. */
  523. function _is_legacy_listener(listener) {
  524. return (listener.name === '_exit' || listener.name === '_uncaughtExceptionThrown')
  525. && listener.toString().indexOf('_garbageCollector();') > -1;
  526. }
  527. /**
  528. * Safely install SIGINT listener.
  529. *
  530. * NOTE: this will only work on OSX and Linux.
  531. *
  532. * @private
  533. */
  534. function _safely_install_sigint_listener() {
  535. const listeners = process.listeners(SIGINT);
  536. const existingListeners = [];
  537. for (let i = 0, length = listeners.length; i < length; i++) {
  538. const lstnr = listeners[i];
  539. /* istanbul ignore else */
  540. if (lstnr.name === '_tmp$sigint_listener') {
  541. existingListeners.push(lstnr);
  542. process.removeListener(SIGINT, lstnr);
  543. }
  544. }
  545. process.on(SIGINT, function _tmp$sigint_listener(doExit) {
  546. for (let i = 0, length = existingListeners.length; i < length; i++) {
  547. // let the existing listener do the garbage collection (e.g. jest sandbox)
  548. try {
  549. existingListeners[i](false);
  550. } catch (err) {
  551. // ignore
  552. }
  553. }
  554. try {
  555. // force the garbage collector even it is called again in the exit listener
  556. _garbageCollector();
  557. } finally {
  558. if (!!doExit) {
  559. process.exit(0);
  560. }
  561. }
  562. });
  563. }
  564. /**
  565. * Safely install process exit listener.
  566. *
  567. * @private
  568. */
  569. function _safely_install_exit_listener() {
  570. const listeners = process.listeners(EXIT);
  571. // collect any existing listeners
  572. const existingListeners = [];
  573. for (let i = 0, length = listeners.length; i < length; i++) {
  574. const lstnr = listeners[i];
  575. /* istanbul ignore else */
  576. // TODO: remove support for legacy listeners once release 1.0.0 is out
  577. if (lstnr.name === '_tmp$safe_listener' || _is_legacy_listener(lstnr)) {
  578. // we must forget about the uncaughtException listener, hopefully it is ours
  579. if (lstnr.name !== '_uncaughtExceptionThrown') {
  580. existingListeners.push(lstnr);
  581. }
  582. process.removeListener(EXIT, lstnr);
  583. }
  584. }
  585. // TODO: what was the data parameter good for?
  586. process.addListener(EXIT, function _tmp$safe_listener(data) {
  587. for (let i = 0, length = existingListeners.length; i < length; i++) {
  588. // let the existing listener do the garbage collection (e.g. jest sandbox)
  589. try {
  590. existingListeners[i](data);
  591. } catch (err) {
  592. // ignore
  593. }
  594. }
  595. _garbageCollector();
  596. });
  597. }
  598. _safely_install_exit_listener();
  599. _safely_install_sigint_listener();
  600. /**
  601. * Configuration options.
  602. *
  603. * @typedef {Object} Options
  604. * @property {?number} tries the number of tries before give up the name generation
  605. * @property {?string} template the "mkstemp" like filename template
  606. * @property {?string} name fix name
  607. * @property {?string} dir the tmp directory to use
  608. * @property {?string} prefix prefix for the generated name
  609. * @property {?string} postfix postfix for the generated name
  610. * @property {?boolean} unsafeCleanup recursively removes the created temporary directory, even when it's not empty
  611. */
  612. /**
  613. * @typedef {Object} FileSyncObject
  614. * @property {string} name the name of the file
  615. * @property {string} fd the file descriptor
  616. * @property {fileCallback} removeCallback the callback function to remove the file
  617. */
  618. /**
  619. * @typedef {Object} DirSyncObject
  620. * @property {string} name the name of the directory
  621. * @property {fileCallback} removeCallback the callback function to remove the directory
  622. */
  623. /**
  624. * @callback tmpNameCallback
  625. * @param {?Error} err the error object if anything goes wrong
  626. * @param {string} name the temporary file name
  627. */
  628. /**
  629. * @callback fileCallback
  630. * @param {?Error} err the error object if anything goes wrong
  631. * @param {string} name the temporary file name
  632. * @param {number} fd the file descriptor
  633. * @param {cleanupCallback} fn the cleanup callback function
  634. */
  635. /**
  636. * @callback dirCallback
  637. * @param {?Error} err the error object if anything goes wrong
  638. * @param {string} name the temporary file name
  639. * @param {cleanupCallback} fn the cleanup callback function
  640. */
  641. /**
  642. * Removes the temporary created file or directory.
  643. *
  644. * @callback cleanupCallback
  645. * @param {simpleCallback} [next] function to call after entry was removed
  646. */
  647. /**
  648. * Callback function for function composition.
  649. * @see {@link https://github.com/raszi/node-tmp/issues/57|raszi/node-tmp#57}
  650. *
  651. * @callback simpleCallback
  652. */
  653. // exporting all the needed methods
  654. // evaluate os.tmpdir() lazily, mainly for simplifying testing but it also will
  655. // allow users to reconfigure the temporary directory
  656. Object.defineProperty(module.exports, 'tmpdir', {
  657. enumerable: true,
  658. configurable: false,
  659. get: function () {
  660. return _getTmpDir();
  661. }
  662. });
  663. module.exports.dir = dir;
  664. module.exports.dirSync = dirSync;
  665. module.exports.file = file;
  666. module.exports.fileSync = fileSync;
  667. module.exports.tmpName = tmpName;
  668. module.exports.tmpNameSync = tmpNameSync;
  669. module.exports.setGracefulCleanup = setGracefulCleanup;