]>
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 | 8 | cleanForExit, |
441b66f8 C |
9 | generateRandomString, |
10 | isTestInstance | |
cbe2f7c3 C |
11 | } |
12 | ||
13 | function generateRandomString (size, callback) { | |
14 | crypto.pseudoRandomBytes(size, function (err, raw) { | |
15 | if (err) return callback(err) | |
16 | ||
17 | callback(null, raw.toString('hex')) | |
18 | }) | |
9f10b292 | 19 | } |
8c308c2b | 20 | |
bc503c2a | 21 | function cleanForExit (webtorrentProcess) { |
9f10b292 | 22 | logger.info('Gracefully exiting.') |
bc503c2a | 23 | process.kill(-webtorrentProcess.pid) |
9f10b292 | 24 | } |
0ae2e7f7 | 25 | |
441b66f8 C |
26 | function isTestInstance () { |
27 | return (process.env.NODE_ENV === 'test') | |
28 | } | |
29 | ||
9f10b292 | 30 | // --------------------------------------------------------------------------- |
c45f7f84 | 31 | |
9f10b292 | 32 | module.exports = utils |