utils.js 367 B

12345678910111213141516171819202122
  1. 'use strict'
  2. const os = require('os')
  3. const path = require('path')
  4. const crypto = require('crypto')
  5. function uuid () {
  6. return crypto.randomBytes(16).toString('hex')
  7. }
  8. function getSock () {
  9. if (process.platform === 'win32') {
  10. return '\\\\.\\pipe\\' + uuid()
  11. } else {
  12. return path.join(os.tmpdir(), uuid())
  13. }
  14. }
  15. module.exports = {
  16. getSock,
  17. uuid
  18. }