utils.js 409 B

1234567891011121314151617181920
  1. const fs = require('fs-extra');
  2. const crypto = require('crypto');
  3. function sleep(ms) {
  4. return new Promise(resolve => setTimeout(resolve, ms));
  5. }
  6. function randomHexString(len) {
  7. return crypto.randomBytes(len).toString('hex')
  8. }
  9. async function touchFile(filename) {
  10. await fs.utimes(filename, Date.now()/1000, Date.now()/1000);
  11. }
  12. module.exports = {
  13. sleep,
  14. randomHexString,
  15. touchFile
  16. };