mime-checking added to magic now

This commit is contained in:
n1073645 2019-12-06 12:24:15 +00:00
parent 0a4fae1576
commit ee37731858
5 changed files with 37 additions and 3 deletions

View file

@ -5,6 +5,7 @@ import Dish from "../Dish.mjs";
import {detectFileType} from "./FileType.mjs";
import chiSquared from "chi-squared";
import potentialOps from "./Test.mjs";
import { isImage } from "./FileType.mjs";
/**
* A class for detecting encodings, file types and byte frequencies and
@ -244,6 +245,23 @@ class Magic {
return results;
}
/**
* Checks the mime value of the data compared to the specified type.
*
* @param {ArrayBuffer} data
* @param {string} type
* @returns {boolean}
*/
async checkMime (data, type) {
switch (type) {
case "Image":
if (isImage(data))
return false;
break;
}
return true;
}
/**
* Uses the checks to validate the input/output of potential operations.
*
@ -276,6 +294,11 @@ class Magic {
return;
}
const mime = OperationConfig[op.op].mimeCheck;
if (mime)
if (await this.checkMime(output, mime.type))
return;
// If the recipe returned an empty buffer, do not continue
if (_buffersEqual(output, new ArrayBuffer())) {
return;