'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();
|