]>
Commit | Line | Data |
---|---|---|
9f10b292 | 1 | 'use strict' |
8c308c2b | 2 | |
cbe2f7c3 C |
3 | const crypto = require('crypto') |
4 | ||
f0f5567b | 5 | const logger = require('./logger') |
8c308c2b | 6 | |
f0f5567b | 7 | const utils = { |
c4403b29 C |
8 | cleanForExit, |
9 | generateRandomString | |
cbe2f7c3 C |
10 | } |
11 | ||
12 | function generateRandomString (size, callback) { | |
13 | crypto.pseudoRandomBytes(size, function (err, raw) { | |
14 | if (err) return callback(err) | |
15 | ||
16 | callback(null, raw.toString('hex')) | |
17 | }) | |
9f10b292 | 18 | } |
8c308c2b | 19 | |
bc503c2a | 20 | function cleanForExit (webtorrentProcess) { |
9f10b292 | 21 | logger.info('Gracefully exiting.') |
bc503c2a | 22 | process.kill(-webtorrentProcess.pid) |
9f10b292 | 23 | } |
0ae2e7f7 | 24 | |
9f10b292 | 25 | // --------------------------------------------------------------------------- |
c45f7f84 | 26 | |
9f10b292 | 27 | module.exports = utils |