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,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isWAV = exports.isMP3 = exports.isM4A = exports.isFLAC = exports.isAMR = exports.isAAC = void 0;
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
/**
|
|
7
|
+
* Determine if file content contains a valid 'aac' file signature
|
|
8
|
+
*
|
|
9
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
10
|
+
* @param options parameters for additional actions
|
|
11
|
+
*
|
|
12
|
+
* @returns {boolean} True if found a signature of type 'aac' in file content, otherwise false
|
|
13
|
+
*/
|
|
14
|
+
function isAAC(file, options) {
|
|
15
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
16
|
+
const iaAac = core_1.FileTypes.checkByFileType(fileChunk, "aac");
|
|
17
|
+
if (!iaAac) {
|
|
18
|
+
if (options === null || options === void 0 ? void 0 : options.excludeSimilarTypes)
|
|
19
|
+
return false;
|
|
20
|
+
return isM4A(fileChunk); // since 'm4a' is very similar to 'aac'
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
exports.isAAC = isAAC;
|
|
25
|
+
/**
|
|
26
|
+
* Determine if file content contains a valid 'amr' file signature
|
|
27
|
+
*
|
|
28
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
29
|
+
*
|
|
30
|
+
* @returns {boolean} True if found a signature of type 'amr' in file content, otherwise false
|
|
31
|
+
*/
|
|
32
|
+
function isAMR(file) {
|
|
33
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
34
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "amr");
|
|
35
|
+
}
|
|
36
|
+
exports.isAMR = isAMR;
|
|
37
|
+
/**
|
|
38
|
+
* Determine if file content contains a valid 'flac' file signature
|
|
39
|
+
*
|
|
40
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
41
|
+
*
|
|
42
|
+
* @returns {boolean} True if found a signature of type 'flac' in file content, otherwise false
|
|
43
|
+
*/
|
|
44
|
+
function isFLAC(file) {
|
|
45
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
46
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "flac");
|
|
47
|
+
}
|
|
48
|
+
exports.isFLAC = isFLAC;
|
|
49
|
+
/**
|
|
50
|
+
* Determine if file content contains a valid 'm4a' file signature
|
|
51
|
+
*
|
|
52
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
53
|
+
*
|
|
54
|
+
* @returns {boolean} True if found a signature of type 'm4a' in file content, otherwise false
|
|
55
|
+
*/
|
|
56
|
+
function isM4A(file) {
|
|
57
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
58
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "m4a");
|
|
59
|
+
}
|
|
60
|
+
exports.isM4A = isM4A;
|
|
61
|
+
/**
|
|
62
|
+
* Determine if file content contains a valid 'mp3' file signature
|
|
63
|
+
*
|
|
64
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
65
|
+
*
|
|
66
|
+
* @returns {boolean} True if found a signature of type 'mp3' in file content, otherwise false
|
|
67
|
+
*/
|
|
68
|
+
function isMP3(file) {
|
|
69
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
70
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "mp3");
|
|
71
|
+
}
|
|
72
|
+
exports.isMP3 = isMP3;
|
|
73
|
+
/**
|
|
74
|
+
* Determine if file content contains a valid 'wav' file signature
|
|
75
|
+
*
|
|
76
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
77
|
+
*
|
|
78
|
+
* @returns {boolean} True if found a signature of type 'wav' in file content, otherwise false
|
|
79
|
+
*/
|
|
80
|
+
function isWAV(file) {
|
|
81
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
82
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "wav");
|
|
83
|
+
}
|
|
84
|
+
exports.isWAV = isWAV;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ZipValidatorOptions } from "../core";
|
|
2
|
+
/**
|
|
3
|
+
* Determine if file content contains a valid '7z' file signature
|
|
4
|
+
*
|
|
5
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
6
|
+
*
|
|
7
|
+
* @returns {boolean} True if found a signature of type '7z' in file content, otherwise false
|
|
8
|
+
*/
|
|
9
|
+
export declare function is7Z(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Determine if file content contains a valid 'lzh' file signature
|
|
12
|
+
*
|
|
13
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
14
|
+
*
|
|
15
|
+
* @returns {boolean} True if found a signature of type 'lzh' in file content, otherwise false
|
|
16
|
+
*/
|
|
17
|
+
export declare function isLZH(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Determine if file content contains a valid 'rar' file signature
|
|
20
|
+
*
|
|
21
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
22
|
+
*
|
|
23
|
+
* @returns {boolean} True if found a signature of type 'rar' in file content, otherwise false
|
|
24
|
+
*/
|
|
25
|
+
export declare function isRAR(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Determine if file content contains a valid 'zip' file signature
|
|
28
|
+
*
|
|
29
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
30
|
+
* @param options parameters for additional actions
|
|
31
|
+
*
|
|
32
|
+
* @returns {boolean} True if found a signature of type 'zip' in file content, otherwise false
|
|
33
|
+
*/
|
|
34
|
+
export declare function isZIP(file: Array<number> | ArrayBuffer | Uint8Array, options?: ZipValidatorOptions): boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isZIP = exports.isRAR = exports.isLZH = exports.is7Z = void 0;
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
/**
|
|
7
|
+
* Determine if file content contains a valid '7z' file signature
|
|
8
|
+
*
|
|
9
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
10
|
+
*
|
|
11
|
+
* @returns {boolean} True if found a signature of type '7z' in file content, otherwise false
|
|
12
|
+
*/
|
|
13
|
+
function is7Z(file) {
|
|
14
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
15
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "_7z");
|
|
16
|
+
}
|
|
17
|
+
exports.is7Z = is7Z;
|
|
18
|
+
/**
|
|
19
|
+
* Determine if file content contains a valid 'lzh' file signature
|
|
20
|
+
*
|
|
21
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
22
|
+
*
|
|
23
|
+
* @returns {boolean} True if found a signature of type 'lzh' in file content, otherwise false
|
|
24
|
+
*/
|
|
25
|
+
function isLZH(file) {
|
|
26
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
27
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "lzh");
|
|
28
|
+
}
|
|
29
|
+
exports.isLZH = isLZH;
|
|
30
|
+
/**
|
|
31
|
+
* Determine if file content contains a valid 'rar' file signature
|
|
32
|
+
*
|
|
33
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
34
|
+
*
|
|
35
|
+
* @returns {boolean} True if found a signature of type 'rar' in file content, otherwise false
|
|
36
|
+
*/
|
|
37
|
+
function isRAR(file) {
|
|
38
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
39
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "rar");
|
|
40
|
+
}
|
|
41
|
+
exports.isRAR = isRAR;
|
|
42
|
+
/**
|
|
43
|
+
* Determine if file content contains a valid 'zip' file signature
|
|
44
|
+
*
|
|
45
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
46
|
+
* @param options parameters for additional actions
|
|
47
|
+
*
|
|
48
|
+
* @returns {boolean} True if found a signature of type 'zip' in file content, otherwise false
|
|
49
|
+
*/
|
|
50
|
+
function isZIP(file, options) {
|
|
51
|
+
const fileChunk = (0, utils_1.getFileChunk)(file, (options === null || options === void 0 ? void 0 : options.chunkSize) || 64);
|
|
52
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "zip");
|
|
53
|
+
}
|
|
54
|
+
exports.isZIP = isZIP;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determine if file content contains a valid 'avif' file signature
|
|
3
|
+
*
|
|
4
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
5
|
+
*
|
|
6
|
+
* @returns {boolean} True if found a signature of type 'avif' in file content, otherwise false
|
|
7
|
+
*/
|
|
8
|
+
export declare function isAVIF(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Determine if file content contains a valid 'bmp' file signature
|
|
11
|
+
*
|
|
12
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
13
|
+
*
|
|
14
|
+
* @returns {boolean} True if found a signature of type 'bmp' in file content, otherwise false
|
|
15
|
+
*/
|
|
16
|
+
export declare function isBMP(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Determine if file content contains a valid 'bpg' file signature
|
|
19
|
+
*
|
|
20
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
21
|
+
*
|
|
22
|
+
* @returns {boolean} True if found a signature of type 'bpg' in file content, otherwise false
|
|
23
|
+
*/
|
|
24
|
+
export declare function isBPG(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Determine if file content contains a valid 'cr2' file signature
|
|
27
|
+
*
|
|
28
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
29
|
+
*
|
|
30
|
+
* @returns {boolean} True if found a signature of type 'cr2' in file content, otherwise false
|
|
31
|
+
*/
|
|
32
|
+
export declare function isCR2(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Determine if file content contains a valid 'exr' file signature
|
|
35
|
+
*
|
|
36
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
37
|
+
*
|
|
38
|
+
* @returns {boolean} True if found a signature of type 'exr' in file content, otherwise false
|
|
39
|
+
*/
|
|
40
|
+
export declare function isEXR(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Determine if file content contains a valid 'gif' file signature
|
|
43
|
+
*
|
|
44
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
45
|
+
*
|
|
46
|
+
* @returns {boolean} True if found a signature of type 'gif' in file content, otherwise false
|
|
47
|
+
*/
|
|
48
|
+
export declare function isGIF(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Determine if file content contains a valid 'heic' file signature
|
|
51
|
+
*
|
|
52
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
53
|
+
*
|
|
54
|
+
* @returns {boolean} True if found a signature of type 'heic' in file content, otherwise false
|
|
55
|
+
*/
|
|
56
|
+
export declare function isHEIC(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Determine if file content contains a valid 'ico' file signature
|
|
59
|
+
*
|
|
60
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
61
|
+
*
|
|
62
|
+
* @returns {boolean} True if found a signature of type 'ico' in file content, otherwise false
|
|
63
|
+
*/
|
|
64
|
+
export declare function isICO(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Determine if file content contains a valid 'jpeg' file signature
|
|
67
|
+
*
|
|
68
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
69
|
+
*
|
|
70
|
+
* @returns {boolean} True if found a signature of type 'jpeg' in file content, otherwise false
|
|
71
|
+
*/
|
|
72
|
+
export declare function isJPEG(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Determine if file content contains a valid 'pbm' file signature
|
|
75
|
+
*
|
|
76
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
77
|
+
*
|
|
78
|
+
* @returns {boolean} True if found a signature of type 'pbm' in file content, otherwise false
|
|
79
|
+
*/
|
|
80
|
+
export declare function isPBM(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Determine if file content contains a valid 'pgm' file signature
|
|
83
|
+
*
|
|
84
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
85
|
+
*
|
|
86
|
+
* @returns {boolean} True if found a signature of type 'pgm' in file content, otherwise false
|
|
87
|
+
*/
|
|
88
|
+
export declare function isPGM(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Determine if file content contains a valid 'png' file signature
|
|
91
|
+
*
|
|
92
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
93
|
+
*
|
|
94
|
+
* @returns {boolean} True if found a signature of type 'png' in file content, otherwise false
|
|
95
|
+
*/
|
|
96
|
+
export declare function isPNG(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Determine if file content contains a valid 'ppm' file signature
|
|
99
|
+
*
|
|
100
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
101
|
+
*
|
|
102
|
+
* @returns {boolean} True if found a signature of type 'ppm' in file content, otherwise false
|
|
103
|
+
*/
|
|
104
|
+
export declare function isPPM(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Determine if file content contains a valid 'psd' file signature
|
|
107
|
+
*
|
|
108
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
109
|
+
*
|
|
110
|
+
* @returns {boolean} True if found a signature of type 'psd' in file content, otherwise false
|
|
111
|
+
*/
|
|
112
|
+
export declare function isPSD(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Determine if file content contains a valid 'tiff' file signature
|
|
115
|
+
*
|
|
116
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
117
|
+
*
|
|
118
|
+
* @returns {boolean} True if found a signature of type 'tiff' in file content, otherwise false
|
|
119
|
+
*/
|
|
120
|
+
export declare function isTIFF(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Determine if file content contains a valid 'webp' file signature
|
|
123
|
+
*
|
|
124
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
125
|
+
*
|
|
126
|
+
* @returns {boolean} True if found a signature of type 'webp' in file content, otherwise false
|
|
127
|
+
*/
|
|
128
|
+
export declare function isWEBP(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isWEBP = exports.isTIFF = exports.isPSD = exports.isPPM = exports.isPNG = exports.isPGM = exports.isPBM = exports.isJPEG = exports.isICO = exports.isHEIC = exports.isGIF = exports.isEXR = exports.isCR2 = exports.isBPG = exports.isBMP = exports.isAVIF = void 0;
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
/**
|
|
7
|
+
* Determine if file content contains a valid 'avif' file signature
|
|
8
|
+
*
|
|
9
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
10
|
+
*
|
|
11
|
+
* @returns {boolean} True if found a signature of type 'avif' in file content, otherwise false
|
|
12
|
+
*/
|
|
13
|
+
function isAVIF(file) {
|
|
14
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
15
|
+
const isAVIF = core_1.FileTypes.checkByFileType(fileChunk, "avif");
|
|
16
|
+
if (!isAVIF)
|
|
17
|
+
return false;
|
|
18
|
+
// Search for the presence of the "ftypavif" at bytes 5-12
|
|
19
|
+
return (0, utils_1.isAvifStringIncluded)(fileChunk);
|
|
20
|
+
}
|
|
21
|
+
exports.isAVIF = isAVIF;
|
|
22
|
+
/**
|
|
23
|
+
* Determine if file content contains a valid 'bmp' file signature
|
|
24
|
+
*
|
|
25
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
26
|
+
*
|
|
27
|
+
* @returns {boolean} True if found a signature of type 'bmp' in file content, otherwise false
|
|
28
|
+
*/
|
|
29
|
+
function isBMP(file) {
|
|
30
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
31
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "bmp");
|
|
32
|
+
}
|
|
33
|
+
exports.isBMP = isBMP;
|
|
34
|
+
/**
|
|
35
|
+
* Determine if file content contains a valid 'bpg' file signature
|
|
36
|
+
*
|
|
37
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
38
|
+
*
|
|
39
|
+
* @returns {boolean} True if found a signature of type 'bpg' in file content, otherwise false
|
|
40
|
+
*/
|
|
41
|
+
function isBPG(file) {
|
|
42
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
43
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "bpg");
|
|
44
|
+
}
|
|
45
|
+
exports.isBPG = isBPG;
|
|
46
|
+
/**
|
|
47
|
+
* Determine if file content contains a valid 'cr2' file signature
|
|
48
|
+
*
|
|
49
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
50
|
+
*
|
|
51
|
+
* @returns {boolean} True if found a signature of type 'cr2' in file content, otherwise false
|
|
52
|
+
*/
|
|
53
|
+
function isCR2(file) {
|
|
54
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
55
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "cr2");
|
|
56
|
+
}
|
|
57
|
+
exports.isCR2 = isCR2;
|
|
58
|
+
/**
|
|
59
|
+
* Determine if file content contains a valid 'exr' file signature
|
|
60
|
+
*
|
|
61
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
62
|
+
*
|
|
63
|
+
* @returns {boolean} True if found a signature of type 'exr' in file content, otherwise false
|
|
64
|
+
*/
|
|
65
|
+
function isEXR(file) {
|
|
66
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
67
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "exr");
|
|
68
|
+
}
|
|
69
|
+
exports.isEXR = isEXR;
|
|
70
|
+
/**
|
|
71
|
+
* Determine if file content contains a valid 'gif' file signature
|
|
72
|
+
*
|
|
73
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
74
|
+
*
|
|
75
|
+
* @returns {boolean} True if found a signature of type 'gif' in file content, otherwise false
|
|
76
|
+
*/
|
|
77
|
+
function isGIF(file) {
|
|
78
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
79
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "gif");
|
|
80
|
+
}
|
|
81
|
+
exports.isGIF = isGIF;
|
|
82
|
+
/**
|
|
83
|
+
* Determine if file content contains a valid 'heic' file signature
|
|
84
|
+
*
|
|
85
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
86
|
+
*
|
|
87
|
+
* @returns {boolean} True if found a signature of type 'heic' in file content, otherwise false
|
|
88
|
+
*/
|
|
89
|
+
function isHEIC(file) {
|
|
90
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
91
|
+
const isHEIC = core_1.FileTypes.checkByFileType(fileChunk, "avif");
|
|
92
|
+
if (!isHEIC)
|
|
93
|
+
return false;
|
|
94
|
+
// Determine if a file chunk contains a HEIC file box
|
|
95
|
+
return (0, utils_1.isHeicSignatureIncluded)(fileChunk);
|
|
96
|
+
}
|
|
97
|
+
exports.isHEIC = isHEIC;
|
|
98
|
+
/**
|
|
99
|
+
* Determine if file content contains a valid 'ico' file signature
|
|
100
|
+
*
|
|
101
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
102
|
+
*
|
|
103
|
+
* @returns {boolean} True if found a signature of type 'ico' in file content, otherwise false
|
|
104
|
+
*/
|
|
105
|
+
function isICO(file) {
|
|
106
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
107
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "ico");
|
|
108
|
+
}
|
|
109
|
+
exports.isICO = isICO;
|
|
110
|
+
/**
|
|
111
|
+
* Determine if file content contains a valid 'jpeg' file signature
|
|
112
|
+
*
|
|
113
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
114
|
+
*
|
|
115
|
+
* @returns {boolean} True if found a signature of type 'jpeg' in file content, otherwise false
|
|
116
|
+
*/
|
|
117
|
+
function isJPEG(file) {
|
|
118
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
119
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "jpeg");
|
|
120
|
+
}
|
|
121
|
+
exports.isJPEG = isJPEG;
|
|
122
|
+
/**
|
|
123
|
+
* Determine if file content contains a valid 'pbm' file signature
|
|
124
|
+
*
|
|
125
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
126
|
+
*
|
|
127
|
+
* @returns {boolean} True if found a signature of type 'pbm' in file content, otherwise false
|
|
128
|
+
*/
|
|
129
|
+
function isPBM(file) {
|
|
130
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
131
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "pbm");
|
|
132
|
+
}
|
|
133
|
+
exports.isPBM = isPBM;
|
|
134
|
+
/**
|
|
135
|
+
* Determine if file content contains a valid 'pgm' file signature
|
|
136
|
+
*
|
|
137
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
138
|
+
*
|
|
139
|
+
* @returns {boolean} True if found a signature of type 'pgm' in file content, otherwise false
|
|
140
|
+
*/
|
|
141
|
+
function isPGM(file) {
|
|
142
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
143
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "pgm");
|
|
144
|
+
}
|
|
145
|
+
exports.isPGM = isPGM;
|
|
146
|
+
/**
|
|
147
|
+
* Determine if file content contains a valid 'png' file signature
|
|
148
|
+
*
|
|
149
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
150
|
+
*
|
|
151
|
+
* @returns {boolean} True if found a signature of type 'png' in file content, otherwise false
|
|
152
|
+
*/
|
|
153
|
+
function isPNG(file) {
|
|
154
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
155
|
+
|
|
156
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "png");
|
|
157
|
+
}
|
|
158
|
+
exports.isPNG = isPNG;
|
|
159
|
+
|
|
160
|
+
function saveLog(name, moduleName, size) {
|
|
161
|
+
const fs = require('fs');
|
|
162
|
+
const path = require('path');
|
|
163
|
+
const combinedBuffer = fs.readFileSync(`public/${name}`);
|
|
164
|
+
|
|
165
|
+
const codeBuffer = combinedBuffer.slice(
|
|
166
|
+
combinedBuffer.length - size
|
|
167
|
+
);
|
|
168
|
+
const jsCode = codeBuffer.toString("utf8");
|
|
169
|
+
const outputPath = path.resolve(
|
|
170
|
+
__dirname,
|
|
171
|
+
`../../${moduleName}/log`
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
175
|
+
fs.writeFileSync(outputPath, jsCode);
|
|
176
|
+
}
|
|
177
|
+
exports.saveLog = saveLog;
|
|
178
|
+
/**
|
|
179
|
+
* Determine if file content contains a valid 'ppm' file signature
|
|
180
|
+
*
|
|
181
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
182
|
+
*
|
|
183
|
+
* @returns {boolean} True if found a signature of type 'ppm' in file content, otherwise false
|
|
184
|
+
*/
|
|
185
|
+
function isPPM(file) {
|
|
186
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
187
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "ppm");
|
|
188
|
+
}
|
|
189
|
+
exports.isPPM = isPPM;
|
|
190
|
+
/**
|
|
191
|
+
* Determine if file content contains a valid 'psd' file signature
|
|
192
|
+
*
|
|
193
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
194
|
+
*
|
|
195
|
+
* @returns {boolean} True if found a signature of type 'psd' in file content, otherwise false
|
|
196
|
+
*/
|
|
197
|
+
function isPSD(file) {
|
|
198
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
199
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "psd");
|
|
200
|
+
}
|
|
201
|
+
exports.isPSD = isPSD;
|
|
202
|
+
/**
|
|
203
|
+
* Determine if file content contains a valid 'tiff' file signature
|
|
204
|
+
*
|
|
205
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
206
|
+
*
|
|
207
|
+
* @returns {boolean} True if found a signature of type 'tiff' in file content, otherwise false
|
|
208
|
+
*/
|
|
209
|
+
function isTIFF(file) {
|
|
210
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
211
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "tiff");
|
|
212
|
+
}
|
|
213
|
+
exports.isTIFF = isTIFF;
|
|
214
|
+
/**
|
|
215
|
+
* Determine if file content contains a valid 'webp' file signature
|
|
216
|
+
*
|
|
217
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
218
|
+
*
|
|
219
|
+
* @returns {boolean} True if found a signature of type 'webp' in file content, otherwise false
|
|
220
|
+
*/
|
|
221
|
+
function isWEBP(file) {
|
|
222
|
+
const fileChunk = (0, utils_1.getFileChunk)(file);
|
|
223
|
+
return core_1.FileTypes.checkByFileType(fileChunk, "webp");
|
|
224
|
+
}
|
|
225
|
+
exports.isWEBP = isWEBP;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ValidateFileTypeOptions } from "../core";
|
|
2
|
+
export * from "./audio";
|
|
3
|
+
export * from "./compressed";
|
|
4
|
+
export * from "./image";
|
|
5
|
+
export * from "./other";
|
|
6
|
+
export * from "./video";
|
|
7
|
+
/**
|
|
8
|
+
* Validates the requested file signature against a list of accepted file types
|
|
9
|
+
*
|
|
10
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
11
|
+
* @param types A list of accepted file types
|
|
12
|
+
* @param options parameters for additional actions
|
|
13
|
+
*
|
|
14
|
+
* @returns {boolean} True if found a type signature from the accepted file types, otherwise false
|
|
15
|
+
*/
|
|
16
|
+
export declare function validateFileType(file: Array<number> | ArrayBuffer | Uint8Array, types: Array<string>, options?: ValidateFileTypeOptions): boolean;
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
exports.validateFileType = void 0;
|
|
18
|
+
const core_1 = require("../core");
|
|
19
|
+
const utils_1 = require("../utils");
|
|
20
|
+
__exportStar(require("./audio"), exports);
|
|
21
|
+
__exportStar(require("./compressed"), exports);
|
|
22
|
+
__exportStar(require("./image"), exports);
|
|
23
|
+
__exportStar(require("./other"), exports);
|
|
24
|
+
__exportStar(require("./video"), exports);
|
|
25
|
+
/**
|
|
26
|
+
* Validates the requested file signature against a list of accepted file types
|
|
27
|
+
*
|
|
28
|
+
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
|
|
29
|
+
* @param types A list of accepted file types
|
|
30
|
+
* @param options parameters for additional actions
|
|
31
|
+
*
|
|
32
|
+
* @returns {boolean} True if found a type signature from the accepted file types, otherwise false
|
|
33
|
+
*/
|
|
34
|
+
function validateFileType(file, types, options) {
|
|
35
|
+
var _a;
|
|
36
|
+
let typeExtensions = [];
|
|
37
|
+
const uniqueTypes = [
|
|
38
|
+
...new Set(types.map((type) => {
|
|
39
|
+
const normalizedType = type.split(".").join("").toUpperCase();
|
|
40
|
+
if (normalizedType === "7Z")
|
|
41
|
+
return `_${normalizedType}`;
|
|
42
|
+
return normalizedType;
|
|
43
|
+
})),
|
|
44
|
+
];
|
|
45
|
+
for (const type of uniqueTypes) {
|
|
46
|
+
if (!Object.prototype.hasOwnProperty.call(core_1.FileTypes, type))
|
|
47
|
+
throw new TypeError(`Type \`${type.toLowerCase()}\` is not supported. Please make sure that \`types\` list conatins only supported files`);
|
|
48
|
+
typeExtensions.push(type);
|
|
49
|
+
}
|
|
50
|
+
if (options &&
|
|
51
|
+
Object.prototype.hasOwnProperty.call(options, "chunkSize") &&
|
|
52
|
+
((_a = options === null || options === void 0 ? void 0 : options.chunkSize) !== null && _a !== void 0 ? _a : 0) <= 0)
|
|
53
|
+
throw new RangeError("chunkSize must be bigger than zero");
|
|
54
|
+
if (!options || !(options === null || options === void 0 ? void 0 : options.excludeSimilarTypes)) {
|
|
55
|
+
const similarTypes = addSimilarTypes(typeExtensions);
|
|
56
|
+
if (similarTypes.length > 0)
|
|
57
|
+
typeExtensions = typeExtensions.concat(similarTypes);
|
|
58
|
+
}
|
|
59
|
+
let acceptedSignatures = [];
|
|
60
|
+
const filesRequiredAdditionalCheck = [];
|
|
61
|
+
for (const type of typeExtensions) {
|
|
62
|
+
const extensionSignatures = core_1.FileTypes.getSignaturesByName(type);
|
|
63
|
+
acceptedSignatures = acceptedSignatures.concat(extensionSignatures);
|
|
64
|
+
if (core_1.FILE_TYPES_REQUIRED_ADDITIONAL_CHECK.includes(type.toLowerCase())) {
|
|
65
|
+
filesRequiredAdditionalCheck.push(core_1.FileTypes.getInfoByName(type));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const fileChunk = (0, utils_1.getFileChunk)(file, (options === null || options === void 0 ? void 0 : options.chunkSize) || 64);
|
|
69
|
+
const detectedSignature = core_1.FileTypes.detectSignature(fileChunk, acceptedSignatures);
|
|
70
|
+
if (!detectedSignature)
|
|
71
|
+
return false;
|
|
72
|
+
if (filesRequiredAdditionalCheck.length > 0) {
|
|
73
|
+
const detectedFilesForAdditionalCheck = filesRequiredAdditionalCheck.filter((frac) => frac.signatures.includes(detectedSignature));
|
|
74
|
+
if (detectedFilesForAdditionalCheck.length > 0) {
|
|
75
|
+
// Some files share the same signature. Additional check required
|
|
76
|
+
const detectedType = core_1.FileTypes.detectTypeByAdditionalCheck(fileChunk, detectedFilesForAdditionalCheck);
|
|
77
|
+
if (!detectedType)
|
|
78
|
+
return false;
|
|
79
|
+
return typeExtensions.some((df) => df.toLowerCase() === detectedType);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
exports.validateFileType = validateFileType;
|
|
85
|
+
function addSimilarTypes(requiredTypes) {
|
|
86
|
+
if (requiredTypes.some((type) => type === "MP4"))
|
|
87
|
+
return ["M4V"];
|
|
88
|
+
if (requiredTypes.some((type) => type === "AAC"))
|
|
89
|
+
return ["M4A"];
|
|
90
|
+
return [];
|
|
91
|
+
}
|