file-type-checker
Version:
Detect and validate file types by their signatures (✨magic numbers✨)
55 lines (54 loc) • 2.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isZIP = exports.isRAR = exports.isLZH = exports.is7Z = void 0;
const core_1 = require("../core");
const utils_1 = require("../utils");
/**
* Determine if file content contains a valid '7z' file signature
*
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
*
* @returns {boolean} True if found a signature of type '7z' in file content, otherwise false
*/
function is7Z(file) {
const fileChunk = (0, utils_1.getFileChunk)(file);
return core_1.FileTypes.checkByFileType(fileChunk, "_7z");
}
exports.is7Z = is7Z;
/**
* Determine if file content contains a valid 'lzh' file signature
*
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
*
* @returns {boolean} True if found a signature of type 'lzh' in file content, otherwise false
*/
function isLZH(file) {
const fileChunk = (0, utils_1.getFileChunk)(file);
return core_1.FileTypes.checkByFileType(fileChunk, "lzh");
}
exports.isLZH = isLZH;
/**
* Determine if file content contains a valid 'rar' file signature
*
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
*
* @returns {boolean} True if found a signature of type 'rar' in file content, otherwise false
*/
function isRAR(file) {
const fileChunk = (0, utils_1.getFileChunk)(file);
return core_1.FileTypes.checkByFileType(fileChunk, "rar");
}
exports.isRAR = isRAR;
/**
* Determine if file content contains a valid 'zip' file signature
*
* @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
* @param options parameters for additional actions
*
* @returns {boolean} True if found a signature of type 'zip' in file content, otherwise false
*/
function isZIP(file, options) {
const fileChunk = (0, utils_1.getFileChunk)(file, (options === null || options === void 0 ? void 0 : options.chunkSize) || 64);
return core_1.FileTypes.checkByFileType(fileChunk, "zip");
}
exports.isZIP = isZIP;