sigcheck 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1081 -0
- package/dist/core/file-types/audio.d.ts +12 -0
- package/dist/core/file-types/audio.js +93 -0
- package/dist/core/file-types/compressed.d.ts +10 -0
- package/dist/core/file-types/compressed.js +155 -0
- package/dist/core/file-types/image.d.ts +22 -0
- package/dist/core/file-types/image.js +248 -0
- package/dist/core/file-types/index.d.ts +109 -0
- package/dist/core/file-types/index.js +215 -0
- package/dist/core/file-types/other.d.ts +21 -0
- package/dist/core/file-types/other.js +234 -0
- package/dist/core/file-types/video.d.ts +15 -0
- package/dist/core/file-types/video.js +153 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +19 -0
- package/dist/core/interfaces/dto/detected-file-info.d.ts +10 -0
- package/dist/core/interfaces/dto/detected-file-info.js +2 -0
- package/dist/core/interfaces/dto/index.d.ts +1 -0
- package/dist/core/interfaces/dto/index.js +17 -0
- package/dist/core/interfaces/index.d.ts +2 -0
- package/dist/core/interfaces/index.js +18 -0
- package/dist/core/interfaces/options/detect-file-options.d.ts +6 -0
- package/dist/core/interfaces/options/detect-file-options.js +2 -0
- package/dist/core/interfaces/options/file-validator-options.d.ts +6 -0
- package/dist/core/interfaces/options/file-validator-options.js +2 -0
- package/dist/core/interfaces/options/index.d.ts +4 -0
- package/dist/core/interfaces/options/index.js +20 -0
- package/dist/core/interfaces/options/validate-file-type-options.d.ts +7 -0
- package/dist/core/interfaces/options/validate-file-type-options.js +2 -0
- package/dist/core/interfaces/options/zip-validator-options.d.ts +6 -0
- package/dist/core/interfaces/options/zip-validator-options.js +2 -0
- package/dist/core/types/file-info.d.ts +10 -0
- package/dist/core/types/file-info.js +2 -0
- package/dist/core/types/file-signature.d.ts +10 -0
- package/dist/core/types/file-signature.js +2 -0
- package/dist/core/types/index.d.ts +2 -0
- package/dist/core/types/index.js +18 -0
- package/dist/detection/index.d.ts +10 -0
- package/dist/detection/index.js +54 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +28 -0
- package/dist/utils/index.d.ts +67 -0
- package/dist/utils/index.js +167 -0
- package/dist/validation/audio.d.ts +50 -0
- package/dist/validation/audio.js +84 -0
- package/dist/validation/compressed.d.ts +34 -0
- package/dist/validation/compressed.js +54 -0
- package/dist/validation/image.d.ts +128 -0
- package/dist/validation/image.js +225 -0
- package/dist/validation/index.d.ts +16 -0
- package/dist/validation/index.js +91 -0
- package/dist/validation/other.d.ts +120 -0
- package/dist/validation/other.js +185 -0
- package/dist/validation/video.d.ts +78 -0
- package/dist/validation/video.js +140 -0
- package/package.json +97 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./detected-file-info"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./dto"), exports);
|
|
18
|
+
__exportStar(require("./options"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./detect-file-options"), exports);
|
|
18
|
+
__exportStar(require("./validate-file-type-options"), exports);
|
|
19
|
+
__exportStar(require("./file-validator-options"), exports);
|
|
20
|
+
__exportStar(require("./zip-validator-options"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./file-info"), exports);
|
|
18
|
+
__exportStar(require("./file-signature"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DetectedFileInfo, DetectFileOptions } from "../core";
|
|
2
|
+
/**
|
|
3
|
+
* Detect a file by searching for a valid file signature inside the file content
|
|
4
|
+
*
|
|
5
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
6
|
+
* @param options Optional parameters for additional actions
|
|
7
|
+
*
|
|
8
|
+
* @returns {DetectedFileInfo | undefined} DetectedFileInfo if detected a valid signature inside the file contentof, otherwise undefined
|
|
9
|
+
*/
|
|
10
|
+
export declare function detectFile(file: Array<number> | ArrayBuffer | Uint8Array, options?: DetectFileOptions): DetectedFileInfo | undefined;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectFile = void 0;
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
/**
|
|
7
|
+
* Detect a file by searching for a valid file signature inside the file content
|
|
8
|
+
*
|
|
9
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
10
|
+
* @param options Optional parameters for additional actions
|
|
11
|
+
*
|
|
12
|
+
* @returns {DetectedFileInfo | undefined} DetectedFileInfo if detected a valid signature inside the file contentof, otherwise undefined
|
|
13
|
+
*/
|
|
14
|
+
function detectFile(file, options) {
|
|
15
|
+
var _a;
|
|
16
|
+
if (options &&
|
|
17
|
+
Object.prototype.hasOwnProperty.call(options, "chunkSize") &&
|
|
18
|
+
((_a = options === null || options === void 0 ? void 0 : options.chunkSize) !== null && _a !== void 0 ? _a : 0) <= 0)
|
|
19
|
+
throw new RangeError("chunkSize must be bigger than zero");
|
|
20
|
+
const fileChunk = (0, utils_1.getFileChunk)(file, (options === null || options === void 0 ? void 0 : options.chunkSize) || 64); // Take chunk from the beginning of the file
|
|
21
|
+
if (fileChunk.length === 0)
|
|
22
|
+
return undefined;
|
|
23
|
+
const detectedFiles = [];
|
|
24
|
+
const filesRequiredAdditionalCheck = [];
|
|
25
|
+
for (const type in core_1.FileTypes) {
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(core_1.FileTypes, type)) {
|
|
27
|
+
const signatures = core_1.FileTypes.getSignaturesByName(type);
|
|
28
|
+
const matchedSignature = core_1.FileTypes.detectbBySignatures(fileChunk, signatures);
|
|
29
|
+
if (matchedSignature) {
|
|
30
|
+
const fileType = core_1.FileTypes.getInfoByName(type);
|
|
31
|
+
if (core_1.FILE_TYPES_REQUIRED_ADDITIONAL_CHECK.includes(fileType.extension)) {
|
|
32
|
+
filesRequiredAdditionalCheck.push(fileType.extension);
|
|
33
|
+
}
|
|
34
|
+
const fileInfo = {
|
|
35
|
+
extension: fileType.extension,
|
|
36
|
+
mimeType: fileType.mimeType,
|
|
37
|
+
description: fileType.description,
|
|
38
|
+
signature: Object.assign(Object.assign({}, matchedSignature), { sequence: matchedSignature.sequence.map((num) => num.toString(16)) }),
|
|
39
|
+
};
|
|
40
|
+
detectedFiles.push(fileInfo);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (detectedFiles.length === 0)
|
|
45
|
+
return undefined;
|
|
46
|
+
if (detectedFiles.length === 1 && filesRequiredAdditionalCheck.length === 0)
|
|
47
|
+
return detectedFiles[0];
|
|
48
|
+
// Some files share the same signature. Additional check required
|
|
49
|
+
const detectedType = core_1.FileTypes.detectTypeByAdditionalCheck(fileChunk, detectedFiles);
|
|
50
|
+
if (!detectedType)
|
|
51
|
+
return undefined;
|
|
52
|
+
return detectedFiles.find((df) => df.extension === detectedType);
|
|
53
|
+
}
|
|
54
|
+
exports.detectFile = detectFile;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
declare const fileTypeChecker: {
|
|
2
|
+
validateFileType(file: number[] | ArrayBuffer | Uint8Array, types: string[], options?: import("./core").ValidateFileTypeOptions | undefined): boolean;
|
|
3
|
+
isAAC(file: number[] | ArrayBuffer | Uint8Array, options?: import("./core").FileValidatorOptions | undefined): boolean;
|
|
4
|
+
isAMR(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
5
|
+
isFLAC(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
6
|
+
isM4A(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
7
|
+
isMP3(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
8
|
+
isWAV(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
9
|
+
is7Z(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
10
|
+
isLZH(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
11
|
+
isRAR(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
12
|
+
isZIP(file: number[] | ArrayBuffer | Uint8Array, options?: import("./core").ZipValidatorOptions | undefined): boolean;
|
|
13
|
+
isAVIF(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
14
|
+
isBMP(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
15
|
+
isBPG(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
16
|
+
isCR2(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
17
|
+
isEXR(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
18
|
+
isGIF(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
19
|
+
isHEIC(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
20
|
+
isICO(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
21
|
+
isJPEG(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
22
|
+
isPBM(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
23
|
+
isPGM(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
24
|
+
isPNG(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
25
|
+
isPPM(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
26
|
+
isPSD(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
27
|
+
isTIFF(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
28
|
+
isWEBP(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
29
|
+
isBLEND(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
30
|
+
isELF(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
31
|
+
isEXE(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
32
|
+
isMACHO(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
33
|
+
isINDD(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
34
|
+
isORC(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
35
|
+
isPARQUET(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
36
|
+
isPDF(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
37
|
+
isPS(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
38
|
+
isRTF(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
39
|
+
isSQLITE(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
40
|
+
isSTL(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
41
|
+
isTTF(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
42
|
+
isDOC(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
43
|
+
isPCAP(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
44
|
+
isAVI(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
45
|
+
isFLV(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
46
|
+
isM4V(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
47
|
+
isMKV(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
48
|
+
isMOV(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
49
|
+
isMP4(file: number[] | ArrayBuffer | Uint8Array, options?: import("./core").FileValidatorOptions | undefined): boolean;
|
|
50
|
+
isOGG(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
51
|
+
isSWF(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
52
|
+
isWEBM(file: number[] | ArrayBuffer | Uint8Array): boolean;
|
|
53
|
+
detectFile(file: number[] | ArrayBuffer | Uint8Array, options?: import("./core").DetectFileOptions | undefined): import("./core").DetectedFileInfo | undefined;
|
|
54
|
+
};
|
|
55
|
+
export = fileTypeChecker;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
const detectionFunctions = __importStar(require("./detection"));
|
|
26
|
+
const validationFunctions = __importStar(require("./validation"));
|
|
27
|
+
const fileTypeChecker = Object.assign(Object.assign({}, detectionFunctions), validationFunctions);
|
|
28
|
+
module.exports = fileTypeChecker;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { FileInfo } from "../core";
|
|
2
|
+
/**
|
|
3
|
+
* Takes a file content in different types, convert it into array of numbers and returns a chunk of the required size
|
|
4
|
+
*
|
|
5
|
+
* @param file - File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
6
|
+
* @param fileChunkLength - Required file chunk length
|
|
7
|
+
*
|
|
8
|
+
* @returns {Array<number>} File chunk of the required size represents in Array<number>
|
|
9
|
+
*/
|
|
10
|
+
export declare function getFileChunk(file: Array<number> | ArrayBuffer | Uint8Array, fileChunkLength?: number): Array<number>;
|
|
11
|
+
/**
|
|
12
|
+
* Fetch a property of a object by its name
|
|
13
|
+
*
|
|
14
|
+
* @param obj The required object
|
|
15
|
+
* @param prop The property name
|
|
16
|
+
*
|
|
17
|
+
* @returns {FileInfo} A property of the rquired object
|
|
18
|
+
*/
|
|
19
|
+
export declare function fetchFromObject(obj: any, prop: string): FileInfo;
|
|
20
|
+
/**
|
|
21
|
+
* Identify whether a valid 'mkv'/'web' file is 'mkv' or 'webm'.
|
|
22
|
+
* By checking for the presence of the "DocType" element in the 'webm' header.
|
|
23
|
+
* Or by checking the presence of the "Segment" element in the 'mkv' header.
|
|
24
|
+
*
|
|
25
|
+
* @param fileChunk - A chunk from the beginning of a file content, represents in array of numbers
|
|
26
|
+
*
|
|
27
|
+
* @returns {string | undefined} 'webm' if found webm string A property of the rquired object
|
|
28
|
+
*/
|
|
29
|
+
export declare function findMatroskaDocTypeElements(fileChunk: Array<number>): string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Determine if array of numbers contains the "fytp" string.
|
|
32
|
+
* M4V files typically have a "ftyp" box in the first few bytes, which can be checked by searching for the string "ftyp" in the buffer.
|
|
33
|
+
*
|
|
34
|
+
* @param fileChunk A chunk from the beginning of a file content, represents in array of numbers
|
|
35
|
+
*
|
|
36
|
+
* @returns {boolean} True if found the "ftyp" string in the fileChunk, otherwise false
|
|
37
|
+
*/
|
|
38
|
+
export declare function isftypStringIncluded(fileChunk: Array<number>): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Determine if array of numbers contains the "FLV" string.
|
|
41
|
+
* FLV files typically have a "FLV" string in the first few bytes of the file, which can be checked using TextDecoder or similar.
|
|
42
|
+
*
|
|
43
|
+
* @param fileChunk A chunk from the beginning of a file content, represents in array of numbers
|
|
44
|
+
*
|
|
45
|
+
* @returns {boolean} True if found the "FLV" string in the fileChunk, otherwise false
|
|
46
|
+
*/
|
|
47
|
+
export declare function isFlvStringIncluded(fileChunk: Array<number>): boolean;
|
|
48
|
+
export declare function isFileContaineJfiforExifHeader(file: number[]): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Determine if array of numbers contains the "ftypavif" string.
|
|
51
|
+
* AVIF files typically have a "ftypavif" string at bytes 5-12 of the file, which can be checked using TextDecoder or similar.
|
|
52
|
+
*
|
|
53
|
+
* @param fileChunk A chunk from the beginning of a file content, represents in array of numbers
|
|
54
|
+
*
|
|
55
|
+
* @returns {boolean} True if found the "AVIF" string in the fileChunk, otherwise false
|
|
56
|
+
*/
|
|
57
|
+
export declare function isAvifStringIncluded(fileChunk: Array<number>): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Determine if a file chunk contains a HEIC file box.
|
|
60
|
+
* HEIC files typically have an 'ftyp' box with specific major brand signatures
|
|
61
|
+
* such as 'heic', 'hevc', 'mif1', and 'msf1' which can be checked by searching
|
|
62
|
+
* for these strings in the file chunk.
|
|
63
|
+
*
|
|
64
|
+
* @param fileChunk A chunk from the beginning of a file content, represented as an array of numbers.
|
|
65
|
+
* @returns {boolean} True if found a HEIC signature in the fileChunk, otherwise false.
|
|
66
|
+
*/
|
|
67
|
+
export declare function isHeicSignatureIncluded(fileChunk: Array<number>): boolean;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isHeicSignatureIncluded = exports.isAvifStringIncluded = exports.isFileContaineJfiforExifHeader = exports.isFlvStringIncluded = exports.isftypStringIncluded = exports.findMatroskaDocTypeElements = exports.fetchFromObject = exports.getFileChunk = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Takes a file content in different types, convert it into array of numbers and returns a chunk of the required size
|
|
6
|
+
*
|
|
7
|
+
* @param file - File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
8
|
+
* @param fileChunkLength - Required file chunk length
|
|
9
|
+
*
|
|
10
|
+
* @returns {Array<number>} File chunk of the required size represents in Array<number>
|
|
11
|
+
*/
|
|
12
|
+
function getFileChunk(file, fileChunkLength = 32 // default length - 32 bytes
|
|
13
|
+
) {
|
|
14
|
+
const fileToCheck = file instanceof ArrayBuffer ? new Uint8Array(file) : file;
|
|
15
|
+
let chunk = [];
|
|
16
|
+
if ((Array.isArray(file) && isArrayofNumbers(file)) ||
|
|
17
|
+
file instanceof ArrayBuffer ||
|
|
18
|
+
file instanceof Uint8Array) {
|
|
19
|
+
chunk = Array.from(fileToCheck.slice(0, fileChunkLength));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
throw new TypeError(`Expected the \`file\` argument to be of type \`Array<number>\`, \`Uint8Array\`, or \`ArrayBuffer\`, got \`${typeof file}\``);
|
|
23
|
+
}
|
|
24
|
+
if (!isLegalChunk(chunk))
|
|
25
|
+
throw new TypeError(`File content contains illegal values`);
|
|
26
|
+
return chunk;
|
|
27
|
+
}
|
|
28
|
+
exports.getFileChunk = getFileChunk;
|
|
29
|
+
/**
|
|
30
|
+
* Determine if array of numbers is a legal file chunk
|
|
31
|
+
*
|
|
32
|
+
* @param fileChunk File content represents in Array<number>
|
|
33
|
+
*
|
|
34
|
+
* @returns {boolean} True if the file content is verified, otherwise false
|
|
35
|
+
*/
|
|
36
|
+
function isLegalChunk(fileChunk) {
|
|
37
|
+
return fileChunk.every((num) => typeof num === "number" && !isNaN(num));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Fetch a property of a object by its name
|
|
41
|
+
*
|
|
42
|
+
* @param obj The required object
|
|
43
|
+
* @param prop The property name
|
|
44
|
+
*
|
|
45
|
+
* @returns {FileInfo} A property of the rquired object
|
|
46
|
+
*/
|
|
47
|
+
// eslint-disable-next-line
|
|
48
|
+
function fetchFromObject(obj, prop) {
|
|
49
|
+
const _index = prop.indexOf(".");
|
|
50
|
+
if (_index > -1) {
|
|
51
|
+
return fetchFromObject(obj[prop.slice(0, _index)], prop.slice(_index + 1));
|
|
52
|
+
}
|
|
53
|
+
return obj[prop];
|
|
54
|
+
}
|
|
55
|
+
exports.fetchFromObject = fetchFromObject;
|
|
56
|
+
/**
|
|
57
|
+
* Identify whether a valid 'mkv'/'web' file is 'mkv' or 'webm'.
|
|
58
|
+
* By checking for the presence of the "DocType" element in the 'webm' header.
|
|
59
|
+
* Or by checking the presence of the "Segment" element in the 'mkv' header.
|
|
60
|
+
*
|
|
61
|
+
* @param fileChunk - A chunk from the beginning of a file content, represents in array of numbers
|
|
62
|
+
*
|
|
63
|
+
* @returns {string | undefined} 'webm' if found webm string A property of the rquired object
|
|
64
|
+
*/
|
|
65
|
+
function findMatroskaDocTypeElements(fileChunk) {
|
|
66
|
+
const webmString = "webm";
|
|
67
|
+
const mkvString = "matroska";
|
|
68
|
+
const byteString = fileChunk.map((num) => String.fromCharCode(num)).join("");
|
|
69
|
+
if (byteString.includes(webmString)) {
|
|
70
|
+
return "webm";
|
|
71
|
+
}
|
|
72
|
+
if (byteString.includes(mkvString)) {
|
|
73
|
+
return "mkv";
|
|
74
|
+
}
|
|
75
|
+
return undefined; // File type not identified
|
|
76
|
+
}
|
|
77
|
+
exports.findMatroskaDocTypeElements = findMatroskaDocTypeElements;
|
|
78
|
+
/**
|
|
79
|
+
* Determine if array of numbers contains the "fytp" string.
|
|
80
|
+
* M4V files typically have a "ftyp" box in the first few bytes, which can be checked by searching for the string "ftyp" in the buffer.
|
|
81
|
+
*
|
|
82
|
+
* @param fileChunk A chunk from the beginning of a file content, represents in array of numbers
|
|
83
|
+
*
|
|
84
|
+
* @returns {boolean} True if found the "ftyp" string in the fileChunk, otherwise false
|
|
85
|
+
*/
|
|
86
|
+
function isftypStringIncluded(fileChunk) {
|
|
87
|
+
const ftypSignature = [0x66, 0x74, 0x79, 0x70]; // "ftyp" signature
|
|
88
|
+
// Check the first few bytes for the "ftyp" signature
|
|
89
|
+
for (let i = 0; i < fileChunk.length - ftypSignature.length; i++) {
|
|
90
|
+
let found = true;
|
|
91
|
+
for (let j = 0; j < ftypSignature.length; j++) {
|
|
92
|
+
if (fileChunk[i + j] !== ftypSignature[j]) {
|
|
93
|
+
found = false;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (found) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
exports.isftypStringIncluded = isftypStringIncluded;
|
|
104
|
+
/**
|
|
105
|
+
* Determine if array of numbers contains the "FLV" string.
|
|
106
|
+
* FLV files typically have a "FLV" string in the first few bytes of the file, which can be checked using TextDecoder or similar.
|
|
107
|
+
*
|
|
108
|
+
* @param fileChunk A chunk from the beginning of a file content, represents in array of numbers
|
|
109
|
+
*
|
|
110
|
+
* @returns {boolean} True if found the "FLV" string in the fileChunk, otherwise false
|
|
111
|
+
*/
|
|
112
|
+
function isFlvStringIncluded(fileChunk) {
|
|
113
|
+
const signature = fileChunk.slice(0, 3);
|
|
114
|
+
const signatureString = new TextDecoder().decode(new Uint8Array(signature));
|
|
115
|
+
return signatureString.includes("FLV");
|
|
116
|
+
}
|
|
117
|
+
exports.isFlvStringIncluded = isFlvStringIncluded;
|
|
118
|
+
function isFileContaineJfiforExifHeader(file) {
|
|
119
|
+
// Check if the fourth byte is one of the known JFIF or EXIF header markers
|
|
120
|
+
const headerMarker = file[3];
|
|
121
|
+
if (headerMarker === 0xe0 || // JFIF
|
|
122
|
+
headerMarker === 0xe1 // EXIF
|
|
123
|
+
) {
|
|
124
|
+
return true; // It's a JPEG file
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
exports.isFileContaineJfiforExifHeader = isFileContaineJfiforExifHeader;
|
|
129
|
+
/**
|
|
130
|
+
* Determine if array of numbers contains the "ftypavif" string.
|
|
131
|
+
* AVIF files typically have a "ftypavif" string at bytes 5-12 of the file, which can be checked using TextDecoder or similar.
|
|
132
|
+
*
|
|
133
|
+
* @param fileChunk A chunk from the beginning of a file content, represents in array of numbers
|
|
134
|
+
*
|
|
135
|
+
* @returns {boolean} True if found the "AVIF" string in the fileChunk, otherwise false
|
|
136
|
+
*/
|
|
137
|
+
function isAvifStringIncluded(fileChunk) {
|
|
138
|
+
// Convert the relevant slice of the file chunk from hexadecimal to characters
|
|
139
|
+
const signature = fileChunk
|
|
140
|
+
.slice(4, 12)
|
|
141
|
+
.map((hex) => String.fromCharCode(hex))
|
|
142
|
+
.join("");
|
|
143
|
+
return signature === "ftypavif";
|
|
144
|
+
}
|
|
145
|
+
exports.isAvifStringIncluded = isAvifStringIncluded;
|
|
146
|
+
// eslint-disable-next-line
|
|
147
|
+
function isArrayofNumbers(arr) {
|
|
148
|
+
return arr.every((element) => typeof element === "number");
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Determine if a file chunk contains a HEIC file box.
|
|
152
|
+
* HEIC files typically have an 'ftyp' box with specific major brand signatures
|
|
153
|
+
* such as 'heic', 'hevc', 'mif1', and 'msf1' which can be checked by searching
|
|
154
|
+
* for these strings in the file chunk.
|
|
155
|
+
*
|
|
156
|
+
* @param fileChunk A chunk from the beginning of a file content, represented as an array of numbers.
|
|
157
|
+
* @returns {boolean} True if found a HEIC signature in the fileChunk, otherwise false.
|
|
158
|
+
*/
|
|
159
|
+
function isHeicSignatureIncluded(fileChunk) {
|
|
160
|
+
// Convert the first part of the file chunk to a string to check for signatures
|
|
161
|
+
const byteString = fileChunk.map((num) => String.fromCharCode(num)).join("");
|
|
162
|
+
// List of possible HEIC 'ftyp' signatures
|
|
163
|
+
const heicSignatures = ["ftypheic", "ftyphevc", "ftypmif1", "ftypmsf1"];
|
|
164
|
+
// Check if any of the HEIC signatures are included in the byte string
|
|
165
|
+
return heicSignatures.some((signature) => byteString.includes(signature));
|
|
166
|
+
}
|
|
167
|
+
exports.isHeicSignatureIncluded = isHeicSignatureIncluded;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { FileValidatorOptions } from "../core";
|
|
2
|
+
/**
|
|
3
|
+
* Determine if file content contains a valid 'aac' file signature
|
|
4
|
+
*
|
|
5
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
6
|
+
* @param options parameters for additional actions
|
|
7
|
+
*
|
|
8
|
+
* @returns {boolean} True if found a signature of type 'aac' in file content, otherwise false
|
|
9
|
+
*/
|
|
10
|
+
export declare function isAAC(file: Array<number> | ArrayBuffer | Uint8Array, options?: FileValidatorOptions): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Determine if file content contains a valid 'amr' file signature
|
|
13
|
+
*
|
|
14
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
15
|
+
*
|
|
16
|
+
* @returns {boolean} True if found a signature of type 'amr' in file content, otherwise false
|
|
17
|
+
*/
|
|
18
|
+
export declare function isAMR(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Determine if file content contains a valid 'flac' file signature
|
|
21
|
+
*
|
|
22
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
23
|
+
*
|
|
24
|
+
* @returns {boolean} True if found a signature of type 'flac' in file content, otherwise false
|
|
25
|
+
*/
|
|
26
|
+
export declare function isFLAC(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Determine if file content contains a valid 'm4a' file signature
|
|
29
|
+
*
|
|
30
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
31
|
+
*
|
|
32
|
+
* @returns {boolean} True if found a signature of type 'm4a' in file content, otherwise false
|
|
33
|
+
*/
|
|
34
|
+
export declare function isM4A(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Determine if file content contains a valid 'mp3' file signature
|
|
37
|
+
*
|
|
38
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
39
|
+
*
|
|
40
|
+
* @returns {boolean} True if found a signature of type 'mp3' in file content, otherwise false
|
|
41
|
+
*/
|
|
42
|
+
export declare function isMP3(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Determine if file content contains a valid 'wav' file signature
|
|
45
|
+
*
|
|
46
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
47
|
+
*
|
|
48
|
+
* @returns {boolean} True if found a signature of type 'wav' in file content, otherwise false
|
|
49
|
+
*/
|
|
50
|
+
export declare function isWAV(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|