all files / pnr-common/lib/node/ fileType.js

96.67% Statements 29/30
90% Branches 9/10
80% Functions 4/5
96.67% Lines 29/30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54          165× 165× 75×   165× 90×   165× 165×   165× 155×         3317×     5546×       195×                
'use strict';
 
const fs = require('fs');
const fileType = exports;
 
// Read file type criteria from the json file and build the relevant
// data structures
fileType.init = function () {
   const criteriaFilePath = __dirname + '/../config/file_type_criteria.json';
   const obj = JSON.parse(fs.readFileSync(criteriaFilePath, 'utf8'));
   const typeList = obj.fileTypes;
   fileType.types = {};
   fileType.docIsoCandidate = [];
   fileType.riskyFiles = [];
   fileType.avCandidate = [];
   fileType.avExtendedCandidate = [];
   for(let item in typeList) {
      fileType.types[item] = item;
      if (typeList[item].docIsoCandidate) {
         fileType.docIsoCandidate.push(item);
      }
      if (typeList[item].riskyFile) {
         fileType.riskyFiles.push(item);
      }
      Eif (typeList[item].avCheckCandidate) {
         fileType.avCandidate.push(item);
      }
      if (typeList[item].avCheckExtendedCandidate) {
         fileType.avExtendedCandidate.push(item);
      }
   }
};
 
fileType.isDocIsoCandidate = function (type) {
   return (this.docIsoCandidate.indexOf(type) >= 0);
};
 
fileType.isAvCandidate = function (type) {
   return (this.avCandidate.indexOf(type) >= 0);
};
 
fileType.isAvExtendedCandidate = function (type) {
   // Defaults to true, unless type explicitly should not.
   return (!fileType.types.hasOwnProperty(type) ||
           this.avExtendedCandidate.indexOf(type) >= 0);
};
 
fileType.isRiskyType = function (type) {
   return (this.riskyFiles.indexOf(type) >= 0);
};
 
// Initialise
fileType.init();