3 const crypto = require('crypto')
5 const logger = require('./logger')
16 function badRequest (req, res, next) {
17 res.type('json').status(400).end()
20 function generateRandomString (size, callback) {
21 crypto.pseudoRandomBytes(size, function (err, raw) {
22 if (err) return callback(err)
24 callback(null, raw.toString('hex'))
28 function cleanForExit (webtorrentProcess) {
29 logger.info('Gracefully exiting.')
30 process.kill(-webtorrentProcess.pid)
33 function createEmptyCallback () {
34 return function (err) {
35 if (err) logger.error('Error in empty callback.', { error: err })
39 function isTestInstance () {
40 return (process.env.NODE_ENV === 'test')
43 function getFormatedObjects (objects, objectsTotal) {
44 const formatedObjects = []
46 objects.forEach(function (object) {
47 formatedObjects.push(object.toFormatedJSON())
56 // ---------------------------------------------------------------------------
58 module.exports = utils